Merge remote-tracking branch 'upstream/dev/0.15.0' into dev/0.15.0

x-dev-15
xwashere 1 year ago
commit 275cb73290
No known key found for this signature in database
GPG Key ID: 042F8BFA1B0EF93B

@ -2,7 +2,7 @@ import { UserConfiguration, UserConfigTypeChecker, PostgresConfiguration, MongoD
import fs from 'fs-extra'; import fs from 'fs-extra';
import { path } from '@tycrek/joint'; import { path } from '@tycrek/joint';
import { log } from './log'; import { log } from './log.js';
const FILEPATH = path.join('.ass-data/userconfig.json'); const FILEPATH = path.join('.ass-data/userconfig.json');

@ -8,15 +8,15 @@ import express, { Request, Response, NextFunction, RequestHandler, json as BodyP
import { path, isProd } from '@tycrek/joint'; import { path, isProd } from '@tycrek/joint';
import { epcss } from '@tycrek/express-postcss'; import { epcss } from '@tycrek/express-postcss';
import { log } from './log'; import { log } from './log.js';
import { get } from './data'; import { get } from './data.js';
import { UserConfig } from './UserConfig'; import { UserConfig } from './UserConfig.js';
import { DBManager } from './sql/database'; import { DBManager } from './sql/database.js';
import { JSONDatabase } from './sql/json'; import { JSONDatabase } from './sql/json.js';
import { MySQLDatabase } from './sql/mysql'; import { MySQLDatabase } from './sql/mysql.js';
import { PostgreSQLDatabase } from './sql/postgres'; import { PostgreSQLDatabase } from './sql/postgres.js';
import { MongoDBDatabase } from './sql/mongodb'; import { MongoDBDatabase } from './sql/mongodb.js';
import { buildFrontendRouter } from './routers/_frontend'; import { buildFrontendRouter } from './routers/_frontend.js';
/** /**
* Top-level metadata exports * Top-level metadata exports

@ -1,8 +1,8 @@
import { AssFile, AssUser, NID } from 'ass'; import { AssFile, AssUser, NID } from 'ass';
import { log } from './log'; import { log } from './log.js';
import { UserConfig } from './UserConfig'; import { UserConfig } from './UserConfig.js';
import { DBManager } from './sql/database'; import { DBManager } from './sql/database.js';
/** /**
* Switcher type for exported functions * Switcher type for exported functions

@ -1,8 +1,8 @@
import { Router } from 'express'; import { Router } from 'express';
import { path } from '@tycrek/joint'; import { path } from '@tycrek/joint';
import { App } from '../app'; import { App } from '../app.js';
import { UserConfig } from '../UserConfig'; import { UserConfig } from '../UserConfig.js';
/** /**
* Builds a basic router for loading a page with frontend JS * Builds a basic router for loading a page with frontend JS
@ -24,7 +24,7 @@ export const buildFrontendRouter = (page: string, onConfigReady = true) => {
// Load frontend JS // Load frontend JS
router.get('/ui.js', (_req, res) => ready() router.get('/ui.js', (_req, res) => ready()
? res.type('text/javascript').sendFile(path.join(`dist-frontend/${page}.mjs`)) ? res.type('text/javascript').sendFile(path.join(`dist/frontend/${page}.mjs`))
: res.sendStatus(403)); : res.sendStatus(403));
return router; return router;

@ -3,16 +3,16 @@ import { AssUser, AssUserNewReq } from 'ass';
import * as bcrypt from 'bcrypt' import * as bcrypt from 'bcrypt'
import { Router, json as BodyParserJson, RequestHandler } from 'express'; import { Router, json as BodyParserJson, RequestHandler } from 'express';
import * as data from '../data'; import * as data from '../data.js';
import { log } from '../log'; import { log } from '../log.js';
import { nanoid } from '../generators'; import { nanoid } from '../generators.js';
import { UserConfig } from '../UserConfig'; import { UserConfig } from '../UserConfig.js';
import { rateLimiterMiddleware, setRateLimiter } from '../ratelimit'; import { rateLimiterMiddleware, setRateLimiter } from '../ratelimit.js';
import { DBManager } from '../sql/database'; import { DBManager } from '../sql/database.js';
import { JSONDatabase } from '../sql/json'; import { JSONDatabase } from '../sql/json.js';
import { MySQLDatabase } from '../sql/mysql'; import { MySQLDatabase } from '../sql/mysql.js';
import { PostgreSQLDatabase } from '../sql/postgres'; import { PostgreSQLDatabase } from '../sql/postgres.js';
import { MongoDBDatabase } from '../sql/mongodb'; import { MongoDBDatabase } from '../sql/mongodb.js';
const router = Router({ caseSensitive: true }); const router = Router({ caseSensitive: true });

@ -6,13 +6,13 @@ import crypto from 'crypto';
import { Router } from 'express'; import { Router } from 'express';
import { Readable } from 'stream'; import { Readable } from 'stream';
import * as data from '../data'; import * as data from '../data.js';
import { log } from '../log'; import { log } from '../log.js';
import { App } from '../app'; import { App } from '../app.js';
import { random } from '../generators'; import { random } from '../generators.js';
import { UserConfig } from '../UserConfig'; import { UserConfig } from '../UserConfig.js';
import { getFileS3, uploadFileS3 } from '../s3'; import { getFileS3, uploadFileS3 } from '../s3.js';
import { rateLimiterMiddleware } from '../ratelimit'; import { rateLimiterMiddleware } from '../ratelimit.js';
const router = Router({ caseSensitive: true }); const router = Router({ caseSensitive: true });

@ -12,8 +12,8 @@ import {
AbortMultipartUploadCommand, AbortMultipartUploadCommand,
} from "@aws-sdk/client-s3"; } from "@aws-sdk/client-s3";
import { log } from './log'; import { log } from './log.js';
import { UserConfig } from './UserConfig'; import { UserConfig } from './UserConfig.js';
const NYR = 'S3 not ready'; const NYR = 'S3 not ready';

@ -3,9 +3,9 @@ import { AssFile, AssUser, FilesSchema, UsersSchema } from 'ass';
import path, { resolve } from 'path'; import path, { resolve } from 'path';
import fs from 'fs-extra'; import fs from 'fs-extra';
import { Database, DatabaseTable, DatabaseValue } from './database'; import { Database, DatabaseTable, DatabaseValue } from './database.js';
import { log } from '../log'; import { log } from '../log.js';
import { nanoid } from '../generators'; import { nanoid } from '../generators.js';
/** /**
* Absolute filepaths for JSON data files * Absolute filepaths for JSON data files

@ -2,9 +2,9 @@ import { AssFile, AssUser, NID, UploadToken } from 'ass';
import mysql, { Pool } from 'mysql2/promise'; import mysql, { Pool } from 'mysql2/promise';
import { log } from '../log'; import { log } from '../log.js';
import { UserConfig } from '../UserConfig'; import { UserConfig } from '../UserConfig.js';
import { Database, DatabaseTable, DatabaseValue } from './database'; import { Database, DatabaseTable, DatabaseValue } from './database.js';
export class MySQLDatabase implements Database { export class MySQLDatabase implements Database {
private _pool: Pool; private _pool: Pool;

@ -1,16 +1,15 @@
import { PostgresConfiguration } from 'ass'; import { PostgresConfiguration } from 'ass';
import { Client } from 'pg'; import pg from 'pg';
import { log } from '../log.js';
import { log } from '../log'; import { Database, DatabaseTable, DatabaseValue } from './database.js';
import { Database, DatabaseTable, DatabaseValue } from './database'; import { UserConfig } from '../UserConfig.js';
import { UserConfig } from '../UserConfig';
/** /**
* database adapter for postgresql * database adapter for postgresql
*/ */
export class PostgreSQLDatabase implements Database { export class PostgreSQLDatabase implements Database {
private _client: Client; private _client: pg.Client;
/** /**
* validate config * validate config
@ -48,7 +47,7 @@ export class PostgreSQLDatabase implements Database {
let config = UserConfig.config.database!.options! as PostgresConfiguration; let config = UserConfig.config.database!.options! as PostgresConfiguration;
// set up the client // set up the client
this._client = new Client({ this._client = new pg.Client({
host: config.host, host: config.host,
port: config.port, port: config.port,
user: config.user, user: config.user,
@ -89,7 +88,7 @@ export class PostgreSQLDatabase implements Database {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
await this._client.query( await this._client.query(
`CREATE TABLE IF NOT EXISTS asstables ( `CREATE TABLE IF NOT EXISTS asstables (
name TEXT PRIMARY KEY, name TEXT PRIMARY KEY,
version INT NOT NULL version INT NOT NULL
);`); );`);

@ -1,7 +1,7 @@
{ {
"extends": "@tsconfig/node20/tsconfig.json", "extends": "@tsconfig/node20/tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "../dist-backend", "outDir": "../dist/backend",
"strictPropertyInitialization": false "strictPropertyInitialization": false
}, },
"include": [ "include": [

@ -1,9 +1,10 @@
const fs = require('fs-extra'); import fs from 'fs-extra';
const { path } = require('@tycrek/joint'); import { path } from '@tycrek/joint';
const log = new (require('@tycrek/log').TLog)(); import { TLog } from '@tycrek/log';
const log = new TLog();
const FILES = { const FILES = {
prefix: 'dist-frontend', prefix: 'dist/frontend',
suffix: '.mjs', suffix: '.mjs',
pages: [ pages: [
'setup', 'setup',

@ -1,7 +1,7 @@
{ {
"extends": "@tsconfig/node20/tsconfig.json", "extends": "@tsconfig/node20/tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "../dist-frontend", "outDir": "../dist/frontend",
"lib": [ "lib": [
"ES2022", "ES2022",
"DOM" "DOM"

@ -2,22 +2,19 @@
"name": "ass", "name": "ass",
"version": "0.15.0-indev", "version": "0.15.0-indev",
"description": "The simple self-hosted ShareX server", "description": "The simple self-hosted ShareX server",
"main": "dist-backend/app.js", "main": "dist/backend/app.js",
"type": "module",
"engines": { "engines": {
"node": "^20", "node": "^20"
"npm": "^10"
}, },
"scripts": { "scripts": {
"dev": "npm run build && npm start", "dev": "npm run build && npm start",
"fresh": "rm -dr .ass-data/ & npm run dev", "fresh": "rm -dr .ass-data/ & npm run dev",
"build": "rm -dr dist-*/ & npm run build:backend && npm run build:frontend", "build": "rm -dr dist/ & npm run build:backend && npm run build:frontend && npm run build:fix-frontend",
"build:backend": "tsc -p backend/", "build:backend": "tsc -p backend/",
"build:frontend": "tsc -p frontend/", "build:frontend": "tsc -p frontend/",
"postbuild:frontend": "node common/fix-frontend-js.js", "build:fix-frontend": "node common/fix-frontend-js.js",
"start": "node dist-backend/app.js", "start": "node dist/backend/app.js"
"cli-setpassword": "node dist/tools/script.setpassword.js",
"cli-testpassword": "node dist/tools/script.testpassword.js",
"cli-adduser": "node dist/tools/script.adduser.js"
}, },
"repository": "github:tycrek/ass", "repository": "github:tycrek/ass",
"keywords": [ "keywords": [
@ -29,13 +26,13 @@
"bugs": "https://github.com/tycrek/ass/issues", "bugs": "https://github.com/tycrek/ass/issues",
"homepage": "https://github.com/tycrek/ass#readme", "homepage": "https://github.com/tycrek/ass#readme",
"dependencies": { "dependencies": {
"@aws-sdk/client-s3": "^3.437.0", "@aws-sdk/client-s3": "^3.456.0",
"@shoelace-style/shoelace": "^2.11.2", "@shoelace-style/shoelace": "^2.12.0",
"@tinycreek/postcss-font-magician": "^4.2.0", "@tinycreek/postcss-font-magician": "^4.2.0",
"@tsconfig/node20": "^20.1.2", "@tsconfig/node20": "^20.1.2",
"@tycrek/discord-hookr": "^0.1.0", "@tycrek/discord-hookr": "^0.1.0",
"@tycrek/express-postcss": "^0.4.1", "@tycrek/express-postcss": "^0.4.1",
"@tycrek/joint": "^1.0.0-1", "@tycrek/joint": "1.0.0-1",
"@tycrek/log": "^0.7.5", "@tycrek/log": "^0.7.5",
"@xoi/gps-metadata-remover": "^1.1.2", "@xoi/gps-metadata-remover": "^1.1.2",
"any-shell-escape": "^0.1.1", "any-shell-escape": "^0.1.1",
@ -45,14 +42,14 @@
"cssnano": "^6.0.1", "cssnano": "^6.0.1",
"express": "^4.18.2", "express": "^4.18.2",
"express-busboy": "^10.1.0", "express-busboy": "^10.1.0",
"express-rate-limit": "^7.1.3", "express-rate-limit": "^7.1.4",
"express-session": "^1.17.3", "express-session": "^1.17.3",
"ffmpeg-static": "^5.2.0", "ffmpeg-static": "^5.2.0",
"fs-extra": "^11.1.1", "fs-extra": "^11.1.1",
"luxon": "^3.4.3", "luxon": "^3.4.4",
"memorystore": "^1.6.7", "memorystore": "^1.6.7",
"mongoose": "^8.0.0", "mongoose": "^8.0.0",
"mysql2": "^3.6.2", "mysql2": "^3.6.5",
"node-vibrant": "^3.1.6", "node-vibrant": "^3.1.6",
"pg": "^8.11.3", "pg": "^8.11.3",
"pug": "^3.0.2", "pug": "^3.0.2",
@ -60,17 +57,17 @@
"shoelace-fontawesome-pug": "^6.4.3", "shoelace-fontawesome-pug": "^6.4.3",
"shoelace-pug-loader": "^2.11.0", "shoelace-pug-loader": "^2.11.0",
"tailwindcss": "^3.3.5", "tailwindcss": "^3.3.5",
"typescript": "^5.2.2" "typescript": "^5.3.2"
}, },
"devDependencies": { "devDependencies": {
"@types/bcrypt": "^5.0.1", "@types/bcrypt": "^5.0.2",
"@types/express": "^4.17.20", "@types/express": "^4.17.21",
"@types/express-busboy": "^8.0.2", "@types/express-busboy": "^8.0.3",
"@types/express-session": "^1.17.9", "@types/express-session": "^1.17.10",
"@types/ffmpeg-static": "^3.0.2", "@types/ffmpeg-static": "^3.0.3",
"@types/fs-extra": "^11.0.3", "@types/fs-extra": "^11.0.4",
"@types/luxon": "^3.3.3", "@types/luxon": "^3.3.5",
"@types/node": "^20.8.9", "@types/node": "^20.10.0",
"@types/pg": "^8.10.7" "@types/pg": "^8.10.9"
} }
} }

File diff suppressed because it is too large Load Diff

@ -41,7 +41,7 @@ const migrate = (authFileName = 'auth.json'): Promise<Users> => new Promise(asyn
const oldUsers = fs.readJsonSync(authPath).users as OldUsers; const oldUsers = fs.readJsonSync(authPath).users as OldUsers;
// Create a new users object // Create a new users object
const newUsers: Users = { users: [], meta: {} }; const newUsers: Users = { users: [], meta: {}, cliKey: nanoid(32) };
newUsers.migrated = true; newUsers.migrated = true;
// Loop through each user // Loop through each user
@ -69,8 +69,9 @@ const migrate = (authFileName = 'auth.json'): Promise<Users> => new Promise(asyn
.catch(reject) .catch(reject)
// Migrate the datafile (token => uploader) // Migrate the datafile (token => uploader)
.then(() => data().get()) .then(() => (!data())
.then((fileData: [string, FileData][]) => ? (log.warn('data.json not found. This may be a new install?'), Promise.resolve())
: data().get().then((fileData: [string, FileData][]) =>
// ! A note about this block. // ! A note about this block.
// I know it's gross. But using Promise.all crashes low-spec servers, so I had to do it this way. Sorry. // I know it's gross. But using Promise.all crashes low-spec servers, so I had to do it this way. Sorry.
@ -100,7 +101,8 @@ const migrate = (authFileName = 'auth.json'): Promise<Users> => new Promise(asyn
runQueue(0); runQueue(0);
})) }))
.catch((err: any) => log.warn(err.message))
)
// We did it hoofuckingray // We did it hoofuckingray
.then(() => log.success('Migrated all auth & file data to new auth system')) .then(() => log.success('Migrated all auth & file data to new auth system'))
.then(() => resolve(newUsers)) .then(() => resolve(newUsers))

Loading…
Cancel
Save