add segfaultapi functionality and use postgres

This commit is contained in:
2022-12-30 19:02:49 +02:00
parent daaca19af8
commit a846dd1e2d
48 changed files with 1576 additions and 377 deletions

View File

@@ -1,6 +1,7 @@
<script>
import HCaptcha from "svelte-hcaptcha";
import { Note } from "$lib/Form";
import config from "$lib/config";
let submit = false;
@@ -14,13 +15,18 @@
icon="i-fa6-solid:circle-info"
/>
<HCaptcha
sitekey="41a7e3f9-595b-494e-ad73-150c410d4a51"
sitekey={config.app.hcaptcha.sitekey}
on:success={showSubmitButton}
/>
<slot />
{#if submit}
<input
<button
type="submit"
value="Submit"
class="form-button"
/>
>
Submit
</button>
{/if}

View File

@@ -36,8 +36,7 @@
{ name: "Contact us", url: "/contact" },
{ name: "Our team", url: "/team" },
{ name: "Timeline", url: "/timeline" },
//{ name: "Blog", url: "/blog" },
{ name: "Blog", url: "https://blog.projectsegfau.lt/", external: true },
{ name: "Blog", url: "/blog" },
{ name: "Legal", url: "/legal" },
{
name: "Status",

24
src/lib/config.ts Normal file
View File

@@ -0,0 +1,24 @@
import { parse } from "yaml";
import fs from "fs";
interface Config {
db: {
url: string;
};
app: {
auth: {
clientId: string;
clientSecret: string;
issuer: string;
}
hcaptcha: {
secret: string;
sitekey: string;
};
webhook: string;
};
}
const config: Config = parse(fs.readFileSync("./config/config.yml", "utf8"));
export default config;

74
src/lib/db.ts Normal file
View File

@@ -0,0 +1,74 @@
import { Sequelize, DataTypes } from "sequelize";
import config from "$lib/config";
import consola from "consola";
const sequelize = new Sequelize(config.db.url);
sequelize.define("Announcements", {
title: {
type: DataTypes.STRING,
allowNull: false
},
severity: {
type: DataTypes.STRING,
allowNull: false
},
author: {
type: DataTypes.STRING,
allowNull: false
},
link: {
type: DataTypes.STRING,
allowNull: true
},
created: {
type: DataTypes.BIGINT,
allowNull: false
}
});
sequelize.define("Posts", {
title: {
type: DataTypes.STRING,
allowNull: false
},
content: {
type: DataTypes.TEXT,
allowNull: false
},
tags: {
type: DataTypes.ARRAY(DataTypes.STRING),
allowNull: false
},
author: {
type: DataTypes.STRING,
allowNull: false
},
created: {
type: DataTypes.BIGINT,
allowNull: false
},
updated: {
type: DataTypes.BIGINT,
allowNull: true,
defaultValue: null
},
words: {
type: DataTypes.INTEGER,
allowNull: false
},
readingTime: {
type: DataTypes.INTEGER,
allowNull: false
}
});
try {
await sequelize.authenticate();
await sequelize.sync();
consola.success("Connected to Postgres");
} catch (error) {
consola.error("Failed to connect to Postgres:", error);
}
export default sequelize;