Compare commits
No commits in common. "9f162e83c43615f2b3de50cde3870cb4eafd027b" and "76bd2a5e1b60fc1aa825ed05660e4fa0651ef8fd" have entirely different histories.
9f162e83c4
...
76bd2a5e1b
|
@ -1,5 +1,5 @@
|
|||
import type { Postgres } from '$lib/server/database/postgres';
|
||||
import { type SimpleGit, CheckRepoActions } from 'simple-git';
|
||||
import type { SimpleGit } from 'simple-git';
|
||||
import fs from 'fs';
|
||||
import compile from '$lib/server/article_compiler';
|
||||
import type { TableSchema } from '$lib/server/database/table';
|
||||
|
@ -11,9 +11,8 @@ const load = async (db: Postgres, git: SimpleGit) => {
|
|||
await db.query('update tag set ref_count = 0');
|
||||
|
||||
await db.begin();
|
||||
let i = 0;
|
||||
for (const { path, id } of articleFiles) {
|
||||
await db.savepoint(`load${i}`);
|
||||
await db.savepoint(id);
|
||||
console.log(`Processing ${id}...`);
|
||||
try {
|
||||
const gitlog = await git.log({
|
||||
|
@ -67,29 +66,38 @@ const load = async (db: Postgres, git: SimpleGit) => {
|
|||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
await db.rollbackTo(`load${i}`);
|
||||
await db.rollbackTo(id);
|
||||
} finally {
|
||||
console.log('');
|
||||
await db.releaseSavepoint(`load${i}`);
|
||||
i++;
|
||||
await db.releaseSavepoint(id);
|
||||
}
|
||||
}
|
||||
await db.commit();
|
||||
}
|
||||
|
||||
export async function init(db: Postgres, git: SimpleGit) {
|
||||
await createTable(db, server_table);
|
||||
await cloneRepo(git);
|
||||
await load(db, git);
|
||||
}
|
||||
|
||||
export async function reload(db: Postgres, git: SimpleGit) {
|
||||
await cloneRepo(git);
|
||||
await load(db, git);
|
||||
}
|
||||
|
||||
type ArticleFileItem = {
|
||||
path: string,
|
||||
id: string,
|
||||
}
|
||||
|
||||
const cloneRepo = async (git: SimpleGit) => {
|
||||
const isRepoRoot = await git.checkIsRepo(CheckRepoActions.IS_REPO_ROOT);
|
||||
if (isRepoRoot) {
|
||||
if (fs.existsSync('./articles/')) {
|
||||
console.log('Pulling articles from git..');
|
||||
await git.pull();
|
||||
} else {
|
||||
console.log('Cloning articles from git..');
|
||||
await git.clone('git@gitea.hareworks.net:Hare/blog-articles.git', './');
|
||||
await git.clone('git@gitea.hareworks.net:Hare/blog-articles.git', 'articles');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,15 +138,4 @@ const crawlArticles = async (db: Postgres): Promise<ArticleFileItem[]> => {
|
|||
}
|
||||
scanDir('./articles/article');
|
||||
return articleFiles;
|
||||
}
|
||||
|
||||
export async function init(db: Postgres, git: SimpleGit) {
|
||||
await createTable(db, server_table);
|
||||
await cloneRepo(git);
|
||||
await load(db, git);
|
||||
}
|
||||
|
||||
export async function reload(db: Postgres, git: SimpleGit) {
|
||||
await cloneRepo(git);
|
||||
await load(db, git);
|
||||
}
|
|
@ -1,9 +1,7 @@
|
|||
import fs from 'fs';
|
||||
import { simpleGit, } from 'simple-git';
|
||||
import type { SimpleGit, SimpleGitOptions } from 'simple-git';
|
||||
|
||||
console.log(process.cwd()+'/articles');
|
||||
fs.mkdirSync(process.cwd()+'/articles', { recursive: true });
|
||||
export const gitOptions: Partial<SimpleGitOptions> = {
|
||||
baseDir: process.cwd()+'/articles',
|
||||
binary: 'git',
|
||||
|
|
Loading…
Reference in New Issue
Block a user