Compare commits

..

No commits in common. "c992579931206d126aff12b61d222611e17673a1" and "c4c645437ffff8dcd0af93b09d143456fa441fc6" have entirely different histories.

2 changed files with 20 additions and 33 deletions

View File

@ -24,7 +24,7 @@ import {
SqliteQueryInterface,
} from "@sequelize/sqlite3";
import { hashpassword } from "@/util/auth";
import { copyFileSync, mkdirSync, readFileSync } from "fs";
import { copyFile, mkdirSync, readFileSync } from "fs";
import path from "path";
import { UUID } from "crypto";
import { runApiAction } from "@/util/api";
@ -76,8 +76,8 @@ async function seedPosts(qif: SqliteQueryInterface<SqliteDialect>) {
],
},
];
projects.map(async (project) => {
await Project.create({
projects.map((project) => {
Project.create({
name: project.name,
readableIdentifier: project.readableIdentifier,
});
@ -90,19 +90,19 @@ async function seedPosts(qif: SqliteQueryInterface<SqliteDialect>) {
user_id: post.user_id,
});
post.buckets.map(async (bucket) => {
await pst.createBucket({ id: bucket.id as UUID });
bucket.attachments.map(async (attachment) => {
await Attachment.create({
pst.createBucket({ id: bucket.id as UUID });
bucket.attachments.map((attachment) => {
Attachment.create({
bucket_id: bucket.id as UUID,
filename: attachment.filename,
}).then(async (a) => {
}).then((a) => {
console.log(bucket.id);
mkdirSync(`./bucket/${bucket.id}/`, { recursive: true });
copyFileSync(
copyFile(
path.resolve(".", "db", "seed", "posts", a.filename),
path.resolve(".", "bucket", bucket.id, a.filename)
path.resolve(".", "bucket", bucket.id, a.filename),
() => {}
);
return;
});
});
});
@ -114,19 +114,19 @@ async function seedPosts(qif: SqliteQueryInterface<SqliteDialect>) {
readableIdentifier: "blog",
},
}).then(
async (project) =>
(project) =>
project ||
(await Project.create({
Project.create({
name: "General Blog",
readableIdentifier: "blog",
}))
})
);
}
async function seedDatabase(qif: SqliteQueryInterface<SqliteDialect>) {
await seedUsers(qif);
await seedPosts(qif);
return;
// await Post.create({
// title: 'Test Post',
// content: `
@ -147,8 +147,8 @@ async function seedDatabase(qif: SqliteQueryInterface<SqliteDialect>) {
// })
}
export async function tryGET(request: Request) {
return await runApiAction(async (request) => {
export async function GET(request: Request) {
runApiAction(async (request) => {
await dbSync;
const queryInterface = sequelize.queryInterface;
@ -161,18 +161,19 @@ export async function tryGET(request: Request) {
case 1:
break;
default:
await seedDatabase(queryInterface);
seedDatabase(queryInterface);
const postsRows: SqliteColumnsDescription = await queryInterface
.describeTable(Post.table.tableName)
.then((t) => t);
if (!postsRows["project_id"])
await queryInterface.addColumn("Posts", "project_id", {
queryInterface.addColumn("Posts", "project_id", {
type: DataTypes.INTEGER,
acceptsNull: () => false,
defaultValue: 1,
});
break;
}
console.log("pp");
return new Response(
JSON.stringify({
test: await queryInterface.describeTable("Posts").then((t) => t),
@ -186,16 +187,3 @@ export async function tryGET(request: Request) {
);
}, request);
}
export async function GET(request: Request) {
try {
return await tryGET(request);
} catch (e) {
if (e instanceof APIError) {
return new Response(e.info.responseText, { status: e.info.status });
} else {
return new Response(JSON.stringify(e));
throw e;
}
}
}

View File

@ -13,12 +13,11 @@ import "@/app/index.css"
import { Post } from "@/models";
import { Attributes } from "@sequelize/core";
import { DeepPartial } from "@/util/deeppartial";
import { constructAPIUrl } from "@/util/url/urlConstructor";
async function getData(slug:string):Promise<Attributes<Post>> {
// Get all posts from the API
const res = await fetch(await constructAPIUrl(`post/${slug}`));
const res = await fetch(`http://localhost:3000/api/post/${slug}`);
// The return value is *not* serialized
// You can return Date, Map, Set, etc.
// Recommendation: handle errors