Compare commits
No commits in common. "9b7d5da439eb452167a55c4907846ff87087d09f" and "30744e3df121c9c259d13ea14742f3574cfcb891" have entirely different histories.
9b7d5da439
...
30744e3df1
2
articles
2
articles
|
@ -1 +1 @@
|
|||
Subproject commit 1af78edd4c4e4e5b3834303e19f3507998019825
|
||||
Subproject commit 172da3590a2e7cec7b41dcf9a60306db277b7159
|
|
@ -1,11 +1,12 @@
|
|||
import pg from 'pg';
|
||||
const { Pool } = pg;
|
||||
import { getConnection } from './database/get_connection';
|
||||
|
||||
export class Postgres {
|
||||
client: pg.PoolClient | null = null;
|
||||
public static async new(pool: pg.Pool) {
|
||||
public static async new(pool: Pool) {
|
||||
const pg = new Postgres();
|
||||
pg.client = await pool.connect();
|
||||
pg.client = await getConnection().connect();
|
||||
return pg;
|
||||
}
|
||||
|
||||
|
@ -31,7 +32,7 @@ export class Postgres {
|
|||
}
|
||||
|
||||
export default async (
|
||||
pool: pg.Pool
|
||||
pool: Pool
|
||||
) => { return await Postgres.new(pool); };
|
||||
|
||||
import { building } from '$app/environment';
|
||||
|
|
|
@ -2,15 +2,8 @@
|
|||
import type { Postgres } from '$lib/server/database';
|
||||
import fs from 'fs';
|
||||
import { compile } from 'mdsvex';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
export default async function init(db: Postgres) {
|
||||
if (fs.existsSync('./articles/')) {
|
||||
console.log('Pulling articles from git..');
|
||||
const stdout = execSync('git pull', { cwd: './articles/' });
|
||||
console.log(stdout.toString());
|
||||
}
|
||||
|
||||
// Create tables(when not exists)
|
||||
const schemas = [
|
||||
{
|
||||
name: 'article',
|
||||
|
@ -114,7 +107,7 @@ export default async function init(db: Postgres) {
|
|||
for (const { path, id } of articleFiles) {
|
||||
const res = await db.query('select * from article where id = $1', [id]);
|
||||
const compiled = await compile(fs.readFileSync(path, 'utf-8'));
|
||||
|
||||
|
||||
const title = compiled.data.fm.title;
|
||||
const category = path.split('/')[3];
|
||||
const tags: string[] = compiled.data.fm.tags;
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
import { json } from '@sveltejs/kit';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
import {
|
||||
TOKEN
|
||||
} from '$env/static/private'
|
||||
|
||||
import PG from '$lib/server/database';
|
||||
import { getConnection } from '$lib/server/database/get_connection';
|
||||
// import { building } from '$app/environment';
|
||||
import init from '$lib/server/database/init_db';
|
||||
|
||||
export const POST: RequestHandler = async ({ url }) => {
|
||||
const token = url.searchParams.get('token');
|
||||
console.log(token);
|
||||
if (token !== TOKEN) {
|
||||
return error(401, 'Unauthorized');
|
||||
}
|
||||
|
||||
await init(await PG(getConnection()));
|
||||
return new Response(String(token));
|
||||
};
|
Loading…
Reference in New Issue
Block a user