Compare commits
No commits in common. "c992579931206d126aff12b61d222611e17673a1" and "c4c645437ffff8dcd0af93b09d143456fa441fc6" have entirely different histories.
c992579931
...
c4c645437f
@ -24,7 +24,7 @@ import {
|
|||||||
SqliteQueryInterface,
|
SqliteQueryInterface,
|
||||||
} from "@sequelize/sqlite3";
|
} from "@sequelize/sqlite3";
|
||||||
import { hashpassword } from "@/util/auth";
|
import { hashpassword } from "@/util/auth";
|
||||||
import { copyFileSync, mkdirSync, readFileSync } from "fs";
|
import { copyFile, mkdirSync, readFileSync } from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { UUID } from "crypto";
|
import { UUID } from "crypto";
|
||||||
import { runApiAction } from "@/util/api";
|
import { runApiAction } from "@/util/api";
|
||||||
@ -76,8 +76,8 @@ async function seedPosts(qif: SqliteQueryInterface<SqliteDialect>) {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
projects.map(async (project) => {
|
projects.map((project) => {
|
||||||
await Project.create({
|
Project.create({
|
||||||
name: project.name,
|
name: project.name,
|
||||||
readableIdentifier: project.readableIdentifier,
|
readableIdentifier: project.readableIdentifier,
|
||||||
});
|
});
|
||||||
@ -90,19 +90,19 @@ async function seedPosts(qif: SqliteQueryInterface<SqliteDialect>) {
|
|||||||
user_id: post.user_id,
|
user_id: post.user_id,
|
||||||
});
|
});
|
||||||
post.buckets.map(async (bucket) => {
|
post.buckets.map(async (bucket) => {
|
||||||
await pst.createBucket({ id: bucket.id as UUID });
|
pst.createBucket({ id: bucket.id as UUID });
|
||||||
bucket.attachments.map(async (attachment) => {
|
bucket.attachments.map((attachment) => {
|
||||||
await Attachment.create({
|
Attachment.create({
|
||||||
bucket_id: bucket.id as UUID,
|
bucket_id: bucket.id as UUID,
|
||||||
filename: attachment.filename,
|
filename: attachment.filename,
|
||||||
}).then(async (a) => {
|
}).then((a) => {
|
||||||
console.log(bucket.id);
|
console.log(bucket.id);
|
||||||
mkdirSync(`./bucket/${bucket.id}/`, { recursive: true });
|
mkdirSync(`./bucket/${bucket.id}/`, { recursive: true });
|
||||||
copyFileSync(
|
copyFile(
|
||||||
path.resolve(".", "db", "seed", "posts", a.filename),
|
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",
|
readableIdentifier: "blog",
|
||||||
},
|
},
|
||||||
}).then(
|
}).then(
|
||||||
async (project) =>
|
(project) =>
|
||||||
project ||
|
project ||
|
||||||
(await Project.create({
|
Project.create({
|
||||||
name: "General Blog",
|
name: "General Blog",
|
||||||
readableIdentifier: "blog",
|
readableIdentifier: "blog",
|
||||||
}))
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function seedDatabase(qif: SqliteQueryInterface<SqliteDialect>) {
|
async function seedDatabase(qif: SqliteQueryInterface<SqliteDialect>) {
|
||||||
await seedUsers(qif);
|
await seedUsers(qif);
|
||||||
await seedPosts(qif);
|
await seedPosts(qif);
|
||||||
return;
|
|
||||||
// await Post.create({
|
// await Post.create({
|
||||||
// title: 'Test Post',
|
// title: 'Test Post',
|
||||||
// content: `
|
// content: `
|
||||||
@ -147,8 +147,8 @@ async function seedDatabase(qif: SqliteQueryInterface<SqliteDialect>) {
|
|||||||
// })
|
// })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function tryGET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
return await runApiAction(async (request) => {
|
runApiAction(async (request) => {
|
||||||
await dbSync;
|
await dbSync;
|
||||||
|
|
||||||
const queryInterface = sequelize.queryInterface;
|
const queryInterface = sequelize.queryInterface;
|
||||||
@ -161,18 +161,19 @@ export async function tryGET(request: Request) {
|
|||||||
case 1:
|
case 1:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
await seedDatabase(queryInterface);
|
seedDatabase(queryInterface);
|
||||||
const postsRows: SqliteColumnsDescription = await queryInterface
|
const postsRows: SqliteColumnsDescription = await queryInterface
|
||||||
.describeTable(Post.table.tableName)
|
.describeTable(Post.table.tableName)
|
||||||
.then((t) => t);
|
.then((t) => t);
|
||||||
if (!postsRows["project_id"])
|
if (!postsRows["project_id"])
|
||||||
await queryInterface.addColumn("Posts", "project_id", {
|
queryInterface.addColumn("Posts", "project_id", {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
acceptsNull: () => false,
|
acceptsNull: () => false,
|
||||||
defaultValue: 1,
|
defaultValue: 1,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
console.log("pp");
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
test: await queryInterface.describeTable("Posts").then((t) => t),
|
test: await queryInterface.describeTable("Posts").then((t) => t),
|
||||||
@ -186,16 +187,3 @@ export async function tryGET(request: 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -13,12 +13,11 @@ import "@/app/index.css"
|
|||||||
import { Post } from "@/models";
|
import { Post } from "@/models";
|
||||||
import { Attributes } from "@sequelize/core";
|
import { Attributes } from "@sequelize/core";
|
||||||
import { DeepPartial } from "@/util/deeppartial";
|
import { DeepPartial } from "@/util/deeppartial";
|
||||||
import { constructAPIUrl } from "@/util/url/urlConstructor";
|
|
||||||
|
|
||||||
|
|
||||||
async function getData(slug:string):Promise<Attributes<Post>> {
|
async function getData(slug:string):Promise<Attributes<Post>> {
|
||||||
// Get all posts from the API
|
// 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
|
// The return value is *not* serialized
|
||||||
// You can return Date, Map, Set, etc.
|
// You can return Date, Map, Set, etc.
|
||||||
// Recommendation: handle errors
|
// Recommendation: handle errors
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user