mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-06 03:26:44 +03:00
@@ -95,6 +95,7 @@ DOCKER_TAG=latest
|
||||
|
||||
# Release and Metadata
|
||||
# MIRROR_RELEASES=false # Mirror GitHub releases
|
||||
# RELEASE_LIMIT=10 # Maximum number of releases to mirror per repository
|
||||
# MIRROR_WIKI=false # Mirror wiki content
|
||||
|
||||
# Issue Tracking (requires MIRROR_METADATA=true)
|
||||
|
||||
@@ -134,6 +134,7 @@ Control what content gets mirrored from GitHub to Gitea.
|
||||
| Variable | Description | Default | Options |
|
||||
|----------|-------------|---------|---------|
|
||||
| `MIRROR_RELEASES` | Mirror GitHub releases | `false` | `true`, `false` |
|
||||
| `RELEASE_LIMIT` | Maximum number of releases to mirror per repository | `10` | Number (1-100) |
|
||||
| `MIRROR_WIKI` | Mirror wiki content | `false` | `true`, `false` |
|
||||
| `MIRROR_METADATA` | Master toggle for metadata mirroring | `false` | `true`, `false` |
|
||||
| `MIRROR_ISSUES` | Mirror issues (requires MIRROR_METADATA=true) | `false` | `true`, `false` |
|
||||
|
||||
@@ -133,6 +133,7 @@ function parseEnvConfig(): EnvConfig {
|
||||
mirrorLabels: process.env.MIRROR_LABELS === 'true',
|
||||
mirrorMilestones: process.env.MIRROR_MILESTONES === 'true',
|
||||
mirrorMetadata: process.env.MIRROR_METADATA === 'true',
|
||||
releaseLimit: process.env.RELEASE_LIMIT ? parseInt(process.env.RELEASE_LIMIT, 10) : undefined,
|
||||
},
|
||||
schedule: {
|
||||
enabled: process.env.SCHEDULE_ENABLED === 'true' ||
|
||||
@@ -271,6 +272,7 @@ export async function initializeConfigFromEnv(): Promise<void> {
|
||||
forkStrategy: envConfig.gitea.forkStrategy || existingConfig?.[0]?.giteaConfig?.forkStrategy || 'reference',
|
||||
// Mirror metadata options
|
||||
mirrorReleases: envConfig.mirror.mirrorReleases ?? existingConfig?.[0]?.giteaConfig?.mirrorReleases ?? false,
|
||||
releaseLimit: envConfig.mirror.releaseLimit ?? existingConfig?.[0]?.giteaConfig?.releaseLimit ?? 10,
|
||||
mirrorMetadata: envConfig.mirror.mirrorMetadata ?? (envConfig.mirror.mirrorIssues || envConfig.mirror.mirrorPullRequests || envConfig.mirror.mirrorLabels || envConfig.mirror.mirrorMilestones) ?? existingConfig?.[0]?.giteaConfig?.mirrorMetadata ?? false,
|
||||
mirrorIssues: envConfig.mirror.mirrorIssues ?? existingConfig?.[0]?.giteaConfig?.mirrorIssues ?? false,
|
||||
mirrorPullRequests: envConfig.mirror.mirrorPullRequests ?? existingConfig?.[0]?.giteaConfig?.mirrorPullRequests ?? false,
|
||||
|
||||
@@ -8,6 +8,7 @@ import { setupSignalHandlers } from './lib/signal-handlers';
|
||||
import { auth } from './lib/auth';
|
||||
import { isHeaderAuthEnabled, authenticateWithHeaders } from './lib/auth-header';
|
||||
import { initializeConfigFromEnv } from './lib/env-config-loader';
|
||||
import { db, users } from './lib/db';
|
||||
|
||||
// Flag to track if recovery has been initialized
|
||||
let recoveryInitialized = false;
|
||||
@@ -17,6 +18,7 @@ let schedulerServiceStarted = false;
|
||||
let repositoryCleanupServiceStarted = false;
|
||||
let shutdownManagerInitialized = false;
|
||||
let envConfigInitialized = false;
|
||||
let envConfigCheckCount = 0; // Track attempts to avoid excessive checking
|
||||
|
||||
export const onRequest = defineMiddleware(async (context, next) => {
|
||||
// First, try Better Auth session (cookie-based)
|
||||
@@ -79,14 +81,31 @@ export const onRequest = defineMiddleware(async (context, next) => {
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize configuration from environment variables (only once)
|
||||
if (!envConfigInitialized) {
|
||||
envConfigInitialized = true;
|
||||
try {
|
||||
await initializeConfigFromEnv();
|
||||
} catch (error) {
|
||||
console.error('⚠️ Failed to initialize configuration from environment:', error);
|
||||
// Continue anyway - environment config is optional
|
||||
// Initialize configuration from environment variables
|
||||
// Optimized to minimize performance impact:
|
||||
// - Once initialized, no checks are performed (envConfigInitialized = true)
|
||||
// - Limits checks to first 100 requests to avoid DB queries on every request if no users exist
|
||||
// - After user creation, env vars load on next request and flag is set permanently
|
||||
if (!envConfigInitialized && envConfigCheckCount < 100) {
|
||||
envConfigCheckCount++;
|
||||
|
||||
// Only check every 10th request after the first 10 to reduce DB load
|
||||
const shouldCheck = envConfigCheckCount <= 10 || envConfigCheckCount % 10 === 0;
|
||||
|
||||
if (shouldCheck) {
|
||||
try {
|
||||
const hasUsers = await db.select().from(users).limit(1).then(u => u.length > 0);
|
||||
|
||||
if (hasUsers) {
|
||||
// We have users now, try to initialize config
|
||||
await initializeConfigFromEnv();
|
||||
envConfigInitialized = true; // This ensures we never check again
|
||||
console.log('✅ Environment configuration loaded after user creation');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('⚠️ Failed to initialize configuration from environment:', error);
|
||||
// Continue anyway - environment config is optional
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user