mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-10 05:26:44 +03:00
@@ -95,6 +95,7 @@ DOCKER_TAG=latest
|
|||||||
|
|
||||||
# Release and Metadata
|
# Release and Metadata
|
||||||
# MIRROR_RELEASES=false # Mirror GitHub releases
|
# MIRROR_RELEASES=false # Mirror GitHub releases
|
||||||
|
# RELEASE_LIMIT=10 # Maximum number of releases to mirror per repository
|
||||||
# MIRROR_WIKI=false # Mirror wiki content
|
# MIRROR_WIKI=false # Mirror wiki content
|
||||||
|
|
||||||
# Issue Tracking (requires MIRROR_METADATA=true)
|
# Issue Tracking (requires MIRROR_METADATA=true)
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ Control what content gets mirrored from GitHub to Gitea.
|
|||||||
| Variable | Description | Default | Options |
|
| Variable | Description | Default | Options |
|
||||||
|----------|-------------|---------|---------|
|
|----------|-------------|---------|---------|
|
||||||
| `MIRROR_RELEASES` | Mirror GitHub releases | `false` | `true`, `false` |
|
| `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_WIKI` | Mirror wiki content | `false` | `true`, `false` |
|
||||||
| `MIRROR_METADATA` | Master toggle for metadata mirroring | `false` | `true`, `false` |
|
| `MIRROR_METADATA` | Master toggle for metadata mirroring | `false` | `true`, `false` |
|
||||||
| `MIRROR_ISSUES` | Mirror issues (requires MIRROR_METADATA=true) | `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',
|
mirrorLabels: process.env.MIRROR_LABELS === 'true',
|
||||||
mirrorMilestones: process.env.MIRROR_MILESTONES === 'true',
|
mirrorMilestones: process.env.MIRROR_MILESTONES === 'true',
|
||||||
mirrorMetadata: process.env.MIRROR_METADATA === 'true',
|
mirrorMetadata: process.env.MIRROR_METADATA === 'true',
|
||||||
|
releaseLimit: process.env.RELEASE_LIMIT ? parseInt(process.env.RELEASE_LIMIT, 10) : undefined,
|
||||||
},
|
},
|
||||||
schedule: {
|
schedule: {
|
||||||
enabled: process.env.SCHEDULE_ENABLED === 'true' ||
|
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',
|
forkStrategy: envConfig.gitea.forkStrategy || existingConfig?.[0]?.giteaConfig?.forkStrategy || 'reference',
|
||||||
// Mirror metadata options
|
// Mirror metadata options
|
||||||
mirrorReleases: envConfig.mirror.mirrorReleases ?? existingConfig?.[0]?.giteaConfig?.mirrorReleases ?? false,
|
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,
|
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,
|
mirrorIssues: envConfig.mirror.mirrorIssues ?? existingConfig?.[0]?.giteaConfig?.mirrorIssues ?? false,
|
||||||
mirrorPullRequests: envConfig.mirror.mirrorPullRequests ?? existingConfig?.[0]?.giteaConfig?.mirrorPullRequests ?? 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 { auth } from './lib/auth';
|
||||||
import { isHeaderAuthEnabled, authenticateWithHeaders } from './lib/auth-header';
|
import { isHeaderAuthEnabled, authenticateWithHeaders } from './lib/auth-header';
|
||||||
import { initializeConfigFromEnv } from './lib/env-config-loader';
|
import { initializeConfigFromEnv } from './lib/env-config-loader';
|
||||||
|
import { db, users } from './lib/db';
|
||||||
|
|
||||||
// Flag to track if recovery has been initialized
|
// Flag to track if recovery has been initialized
|
||||||
let recoveryInitialized = false;
|
let recoveryInitialized = false;
|
||||||
@@ -17,6 +18,7 @@ let schedulerServiceStarted = false;
|
|||||||
let repositoryCleanupServiceStarted = false;
|
let repositoryCleanupServiceStarted = false;
|
||||||
let shutdownManagerInitialized = false;
|
let shutdownManagerInitialized = false;
|
||||||
let envConfigInitialized = false;
|
let envConfigInitialized = false;
|
||||||
|
let envConfigCheckCount = 0; // Track attempts to avoid excessive checking
|
||||||
|
|
||||||
export const onRequest = defineMiddleware(async (context, next) => {
|
export const onRequest = defineMiddleware(async (context, next) => {
|
||||||
// First, try Better Auth session (cookie-based)
|
// First, try Better Auth session (cookie-based)
|
||||||
@@ -79,16 +81,33 @@ export const onRequest = defineMiddleware(async (context, next) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize configuration from environment variables (only once)
|
// Initialize configuration from environment variables
|
||||||
if (!envConfigInitialized) {
|
// Optimized to minimize performance impact:
|
||||||
envConfigInitialized = true;
|
// - 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 {
|
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();
|
await initializeConfigFromEnv();
|
||||||
|
envConfigInitialized = true; // This ensures we never check again
|
||||||
|
console.log('✅ Environment configuration loaded after user creation');
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('⚠️ Failed to initialize configuration from environment:', error);
|
console.error('⚠️ Failed to initialize configuration from environment:', error);
|
||||||
// Continue anyway - environment config is optional
|
// Continue anyway - environment config is optional
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize recovery system only once when the server starts
|
// Initialize recovery system only once when the server starts
|
||||||
// This is a fallback in case the startup script didn't run
|
// This is a fallback in case the startup script didn't run
|
||||||
|
|||||||
Reference in New Issue
Block a user