/ opencodehub / scripts / manual-sync.ts
swadhinbiswas feat: OpenCodeHub v1.1.0 - Enterprise Features & Storage Adapters · 2/15/2026
719a1cb
32 lines · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { join } from "path";
import { readdirSync, statSync } from "fs";
import { uploadRepoToStorage, getStorageRepoPath, isCloudStorage } from "@/lib/git-storage";

const REPOS_DIR = join(process.cwd(), "data", "repos");

async function main() {
    if (!await isCloudStorage()) {
        console.log("Not using cloud storage. No sync needed.");
        return;
    }

    const owners = readdirSync(REPOS_DIR);
    for (const owner of owners) {
        const ownerPath = join(REPOS_DIR, owner);
        if (!statSync(ownerPath).isDirectory()) continue;

        const repos = readdirSync(ownerPath);
        for (const repo of repos) {
            if (!repo.endsWith(".git")) continue;
            const repoName = repo.replace(".git", "");
            console.log(`Syncing ${owner}/${repoName}...`);
            try {
                await uploadRepoToStorage(join(ownerPath, repo), getStorageRepoPath(owner, repoName));
            } catch (e) {
                console.error(`Failed to sync ${owner}/${repoName}:`, e);
            }
        }
    }
}
main().catch(console.error);