Setup the DB properly
This commit is contained in:
parent
35680e719b
commit
0b5bc42587
4 changed files with 60 additions and 22 deletions
|
|
@ -45,6 +45,7 @@
|
||||||
"libcurl.js-new": "npm:libcurl.js@^0.6.16",
|
"libcurl.js-new": "npm:libcurl.js@^0.6.16",
|
||||||
"multer": "1.4.5-lts.1",
|
"multer": "1.4.5-lts.1",
|
||||||
"nanostores": "^0.10.3",
|
"nanostores": "^0.10.3",
|
||||||
|
"ora": "^8.1.0",
|
||||||
"pg": "^8.13.0",
|
"pg": "^8.13.0",
|
||||||
"pg-hstore": "^2.3.4",
|
"pg-hstore": "^2.3.4",
|
||||||
"sequelize": "^6.37.4",
|
"sequelize": "^6.37.4",
|
||||||
|
|
|
||||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
|
|
@ -95,6 +95,9 @@ importers:
|
||||||
nanostores:
|
nanostores:
|
||||||
specifier: ^0.10.3
|
specifier: ^0.10.3
|
||||||
version: 0.10.3
|
version: 0.10.3
|
||||||
|
ora:
|
||||||
|
specifier: ^8.1.0
|
||||||
|
version: 8.1.0
|
||||||
pg:
|
pg:
|
||||||
specifier: ^8.13.0
|
specifier: ^8.13.0
|
||||||
version: 8.13.0
|
version: 8.13.0
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,54 @@
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
import { CatalogModel } from "./server.js";
|
import { CatalogModel, Catalog } from "./server.js";
|
||||||
import { ModelCtor } from "sequelize";
|
import { ModelStatic } from "sequelize";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
import ora from 'ora';
|
||||||
|
|
||||||
function setupDB(db: ModelCtor<CatalogModel>) {
|
interface Items extends Omit<Catalog, "background_video" | "background_image"> {
|
||||||
|
background_video?: string
|
||||||
|
background_image?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
async function installItems(db: ModelStatic<CatalogModel>, items: Items[]) {
|
||||||
|
items.forEach(async (item) => {
|
||||||
|
await db.create({
|
||||||
|
package_name: item.package_name,
|
||||||
|
title: item.title,
|
||||||
|
image: item.image,
|
||||||
|
author: item.author,
|
||||||
|
version: item.author,
|
||||||
|
description: item.description,
|
||||||
|
tags: item.tags,
|
||||||
|
payload: item.payload,
|
||||||
|
background_video: item.background_video,
|
||||||
|
background_image: item.background_image,
|
||||||
|
type: item.type
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setupDB(db: ModelStatic<CatalogModel>) {
|
||||||
//We have some packages that need to be installed if they aren't.
|
//We have some packages that need to be installed if they aren't.
|
||||||
//TODO: set this up
|
const items: Items[] = [
|
||||||
console.log(chalk.hex('#7967dd')('Performing DB setup...'));
|
{
|
||||||
//db.create({
|
package_name: 'com.nebula.cybermonay',
|
||||||
// package_name: 'com.nebula.cybermonay',
|
title: 'Cyber Monay',
|
||||||
// title: 'Cyber Monay',
|
image: 'cyber_monay.jpg',
|
||||||
// image: 'cyber_monay.jpg',
|
author: 'Nebula Services',
|
||||||
// author: 'Nebula Services',
|
version: '1.0.0',
|
||||||
// version: '1.0.0',
|
description: 'A parody of the famous "Cyber Monay" hack!',
|
||||||
// description: 'A parody of the famous "Cyber Monay" hack!',
|
tags: ["Hacking", "Animated", "Funny"],
|
||||||
// tags: ["Hacking", "Animated", "Funny"],
|
payload: "com.nebula.cybermonay.css",
|
||||||
// payload: "com.nebula.cybermonay.css",
|
background_video: "cyber_monay_test.mp4",
|
||||||
// background_video: "cyber_monay_test.mp4",
|
type: 'theme'
|
||||||
// type: 'theme'
|
}
|
||||||
//});
|
]
|
||||||
|
const dbItems = await db.findAll();
|
||||||
|
if (dbItems.length === 0) {
|
||||||
|
const spinner = ora(chalk.hex('#7967dd')('Performing DB setup...')).start();
|
||||||
|
await installItems(db, items);
|
||||||
|
spinner.succeed(chalk.hex('#eb6f92')('DB setup complete!'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { setupDB }
|
export { setupDB }
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ const db = new Sequelize(parsedDoc.db.name, parsedDoc.db.username, parsedDoc.db.
|
||||||
storage: 'database.sqlite' //this is sqlite only
|
storage: 'database.sqlite' //this is sqlite only
|
||||||
});
|
});
|
||||||
|
|
||||||
interface CatalogModel extends Model<InferAttributes<CatalogModel>, InferCreationAttributes<CatalogModel>> {
|
interface Catalog {
|
||||||
package_name: string
|
package_name: string
|
||||||
title: string
|
title: string
|
||||||
description: string
|
description: string
|
||||||
|
|
@ -37,6 +37,9 @@ interface CatalogModel extends Model<InferAttributes<CatalogModel>, InferCreatio
|
||||||
payload: string
|
payload: string
|
||||||
type: string
|
type: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface CatalogModel extends Catalog, Model<InferAttributes<CatalogModel>, InferCreationAttributes<CatalogModel>> {};
|
||||||
|
|
||||||
const catalogAssets = db.define<CatalogModel>("catalog_assets", {
|
const catalogAssets = db.define<CatalogModel>("catalog_assets", {
|
||||||
package_name: { type: DataTypes.TEXT, unique: true },
|
package_name: { type: DataTypes.TEXT, unique: true },
|
||||||
title: { type: DataTypes.TEXT },
|
title: { type: DataTypes.TEXT },
|
||||||
|
|
@ -254,11 +257,11 @@ const titleColors = {
|
||||||
|
|
||||||
|
|
||||||
console.log(gradient(Object.values(titleColors)).multiline(titleText as string));
|
console.log(gradient(Object.values(titleColors)).multiline(titleText as string));
|
||||||
app.listen({ port: port, host: '0.0.0.0' }).then(() => {
|
app.listen({ port: port, host: '0.0.0.0' }).then(async () => {
|
||||||
console.log(chalk.hex('#7967dd')(`Server listening on ${chalk.hex('#eb6f92').bold('http://localhost:' + port + '/')}`));
|
console.log(chalk.hex('#7967dd')(`Server listening on ${chalk.hex('#eb6f92').bold('http://localhost:' + port + '/')}`));
|
||||||
console.log(chalk.hex('#7967dd')(`Server also listening on ${chalk.hex('#eb6f92').bold('http://0.0.0.0:' + port + '/')}`));
|
console.log(chalk.hex('#7967dd')(`Server also listening on ${chalk.hex('#eb6f92').bold('http://0.0.0.0:' + port + '/')}`));
|
||||||
catalogAssets.sync();
|
await catalogAssets.sync()
|
||||||
setupDB(catalogAssets);
|
await setupDB(catalogAssets);
|
||||||
});
|
});
|
||||||
|
|
||||||
export { CatalogModel }
|
export { CatalogModel, Catalog }
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue