article update automation #4
2
articles
2
articles
|
@ -1 +1 @@
|
|||
Subproject commit 172da3590a2e7cec7b41dcf9a60306db277b7159
|
||||
Subproject commit 1af78edd4c4e4e5b3834303e19f3507998019825
|
|
@ -1,12 +1,11 @@
|
|||
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: Pool) {
|
||||
public static async new(pool: pg.Pool) {
|
||||
const pg = new Postgres();
|
||||
pg.client = await getConnection().connect();
|
||||
pg.client = await pool.connect();
|
||||
return pg;
|
||||
}
|
||||
|
||||
|
@ -32,7 +31,7 @@ export class Postgres {
|
|||
}
|
||||
|
||||
export default async (
|
||||
pool: Pool
|
||||
pool: pg.Pool
|
||||
) => { return await Postgres.new(pool); };
|
||||
|
||||
import { building } from '$app/environment';
|
||||
|
|
|
@ -2,8 +2,15 @@
|
|||
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) {
|
||||
// Create tables(when not exists)
|
||||
if (fs.existsSync('./articles/')) {
|
||||
console.log('Pulling articles from git..');
|
||||
const stdout = execSync('git pull', { cwd: './articles/' });
|
||||
console.log(stdout.toString());
|
||||
}
|
||||
|
||||
const schemas = [
|
||||
{
|
||||
name: 'article',
|
||||
|
|
23
src/routes/api/fetch_articles/+server.ts
Normal file
23
src/routes/api/fetch_articles/+server.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
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