mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
wip: replace packages with pure files
This commit is contained in:
1 parent
2d95ca382f
commit
87b8ca5d04
112 files changed
+740
-522
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import connectDB, { User } from '@linux-odyssey/models'
|
||||
import connectDB, { User } from '@models'
|
||||
|
||||
async function migrate() {
|
||||
await connectDB(
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"watch": ["src", "swagger.yaml", "../quests", "../packages"],
|
||||
"ext": "js,ts,yaml,yml",
|
||||
"exec": "node --loader ts-node/esm src/index.js"
|
||||
}
|
||||
+7
-15
@@ -2,22 +2,15 @@
|
||||
"name": "server",
|
||||
"version": "0.0.0",
|
||||
"description": "Linux Odyssey Server",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node dist/index.js",
|
||||
"setup": "node dist/cli/setup.js",
|
||||
"clean": "node dist/cli/clean.js",
|
||||
"build": "tsc -b",
|
||||
"dev": "nodemon",
|
||||
"build:quests": "node dist/cli/build.js",
|
||||
"ts-node": "node --loader ts-node/esm"
|
||||
"start": "tsx src/index.ts",
|
||||
"setup": "tsx src/cli/setup.js",
|
||||
"clean": "tsx src/cli/clean.js",
|
||||
"type-check": "tsc --noEmit",
|
||||
"dev": "tsx --watch src/index.ts",
|
||||
"build:quests": "tsx src/cli/build.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@linux-odyssey/constants": "*",
|
||||
"@linux-odyssey/game": "*",
|
||||
"@linux-odyssey/file-graph": "*",
|
||||
"@linux-odyssey/models": "*",
|
||||
"@linux-odyssey/utils": "*",
|
||||
"@trpc/server": "^11.1.0",
|
||||
"bcrypt": "^5.1.1",
|
||||
"commander": "^11.0.0",
|
||||
@@ -44,6 +37,7 @@
|
||||
"socket.io": "^4.7.1",
|
||||
"ssh2": "^1.16.0",
|
||||
"swagger-ui-express": "^5.0.0",
|
||||
"tsx": "^4.19.3",
|
||||
"validator": "^13.11.0",
|
||||
"winston": "^3.11.0",
|
||||
"yaml": "^2.3.1",
|
||||
@@ -70,10 +64,8 @@
|
||||
"@types/validator": "^13.11.9",
|
||||
"concurrently": "^8.2.2",
|
||||
"jest": "^29.6.1",
|
||||
"nodemon": "^3.0.1",
|
||||
"regenerator-runtime": "^0.14.1",
|
||||
"source-map-support": "^0.5.21",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import { GameSession, commandSchema } from '@linux-odyssey/game'
|
||||
import { Command, Session } from '@linux-odyssey/models'
|
||||
import { GameSession, commandSchema } from '../../../../packages/game'
|
||||
import { Command, Session } from '../../../../packages/models'
|
||||
import type { Request, Response } from 'express'
|
||||
import { pushToSession } from '../socket.js'
|
||||
import { finishSession } from '../../models/sessionManager.js'
|
||||
import { asyncHandler } from '../../middleware/error.js'
|
||||
import { questManager } from '../../models/quest.js'
|
||||
import { CLIFileExistenceChecker } from '../../containers/cli.js'
|
||||
import { pushToSession } from '../socket'
|
||||
import { finishSession } from '../../models/sessionManager'
|
||||
import { asyncHandler } from '../../middleware/error'
|
||||
import { questManager } from '../../models/quest'
|
||||
import { CLIFileExistenceChecker } from '../../containers/cli'
|
||||
|
||||
export const newCommand = asyncHandler(async (req: Request, res: Response) => {
|
||||
const command = commandSchema.parse(req.body)
|
||||
|
||||
@@ -4,7 +4,7 @@ import { leaderboard } from '../../models/userManager.js'
|
||||
|
||||
export default asyncHandler(async (req: Request, res: Response) => {
|
||||
const users = await leaderboard()
|
||||
const response = users.map((user) => ({
|
||||
const response = users.map((user: any) => ({
|
||||
username: user.user.username,
|
||||
completedQuests: user.completedQuests,
|
||||
score: user.score * 1000,
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { Socket } from 'socket.io'
|
||||
import { Duplex } from 'stream'
|
||||
import validator from 'validator'
|
||||
import type { Server as HttpServer } from 'http'
|
||||
import { ISession, Session } from '@linux-odyssey/models'
|
||||
import { ISession, Session } from '../../../packages/models'
|
||||
import { getAndStartContainer, attachContainer } from '../containers/docker.js'
|
||||
import SessionMiddleware from '../middleware/session.js'
|
||||
import { genJWT } from '../utils/auth.js'
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { check } from 'express-validator'
|
||||
|
||||
import { isValidUsername, isValidEmail } from '@linux-odyssey/utils'
|
||||
import { User } from '@linux-odyssey/models'
|
||||
import { passwordPolicy } from '@linux-odyssey/constants'
|
||||
import { isValidUsername, isValidEmail } from '../../../../packages/utils'
|
||||
import { User } from '../../../../packages/models'
|
||||
import { passwordPolicy } from '../../../../packages/constants'
|
||||
import { noError } from '../../middleware/validator.js'
|
||||
|
||||
const checkUsername = () =>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { User } from '@linux-odyssey/models'
|
||||
import { User } from '../../../packages/models'
|
||||
import type { Profile } from 'passport'
|
||||
import type { VerifyCallback } from 'passport-oauth2'
|
||||
import logger from '../utils/logger.js'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import passport from 'passport'
|
||||
import type { Express } from 'express'
|
||||
import { UserProfile } from '@linux-odyssey/models'
|
||||
import { UserProfile } from '../../../packages/models'
|
||||
import passwordStrategy from './passwordStrategy.js'
|
||||
import jwtStrategy from './jwtStrategy.js'
|
||||
import googleStrategy from './googleStrategy.js'
|
||||
|
||||
@@ -3,7 +3,7 @@ import bcrypt from 'bcrypt'
|
||||
import { Strategy as LocalStrategy } from 'passport-local'
|
||||
import type { IVerifyOptions } from 'passport-local'
|
||||
import type { Express } from 'express'
|
||||
import { User } from '@linux-odyssey/models'
|
||||
import { User } from '../../../packages/models'
|
||||
|
||||
async function verifyPassword(
|
||||
username: string,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import connectDB from '@linux-odyssey/models'
|
||||
import { removeExpired } from '../containers/expiryChecker.js'
|
||||
import config from '../config.js'
|
||||
import logger from '../utils/logger.js'
|
||||
import connectDB from '../../../packages/models'
|
||||
import { removeExpired } from '../containers/expiryChecker'
|
||||
import config from '../config'
|
||||
import logger from '../utils/logger'
|
||||
|
||||
connectDB(config.db)
|
||||
.then(removeExpired)
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import validator from 'validator'
|
||||
import dotenv from 'dotenv'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { config as dotenvConfig } from 'dotenv'
|
||||
import path from 'path'
|
||||
import { get } from './utils/env.js'
|
||||
import { loadOrCreateKeyPair } from './utils/crypto.js'
|
||||
|
||||
// Import dotenv and load ../.env
|
||||
dotenv.config({ path: '../.env' })
|
||||
dotenvConfig({ path: '../.env' })
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
dotenv.config({ path: '../.env.dev' })
|
||||
dotenvConfig({ path: '../.env.dev' })
|
||||
}
|
||||
|
||||
function getTrustProxies(key: string): string[] {
|
||||
@@ -93,8 +92,7 @@ function createConfig() {
|
||||
}
|
||||
|
||||
function getProjectRoot(): string {
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const root = path.join(path.dirname(filename), '..', '..')
|
||||
const root = path.join(path.dirname(__filename), '..', '..')
|
||||
return root
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { execFile } from 'child_process'
|
||||
|
||||
import { buildFileCheckCmd } from '@linux-odyssey/utils'
|
||||
import type { IFileExistenceChecker, IFileInput } from '@linux-odyssey/game'
|
||||
import { buildFileCheckCmd } from '../../../packages/utils'
|
||||
import type { IFileExistenceChecker, IFileInput } from '../../../packages/game'
|
||||
|
||||
function sanitizeId(id: string) {
|
||||
return id.replace(/[^a-zA-Z0-9]/g, '')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import schedule from 'node-schedule'
|
||||
import { Session } from '@linux-odyssey/models'
|
||||
import type { ISession } from '@linux-odyssey/models'
|
||||
import { Session } from '../../../packages/models'
|
||||
import type { ISession } from '../../../packages/models'
|
||||
import type { HydratedDocument } from 'mongoose'
|
||||
import config from '../config.js'
|
||||
import { deleteContainer } from './docker.js'
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import YAML from 'yaml'
|
||||
import swaggerUI from 'swagger-ui-express'
|
||||
import passport from 'passport'
|
||||
import * as trpcExpress from '@trpc/server/adapters/express'
|
||||
import connectDB from '@linux-odyssey/models'
|
||||
import connectDB from '../../packages/models'
|
||||
|
||||
import './auth/passport.js'
|
||||
import socketServer from './api/socket.js'
|
||||
|
||||
@@ -3,7 +3,11 @@ import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
import yaml from 'yaml'
|
||||
|
||||
import { questSchema, globalExceptionSchema, IQuest } from '@linux-odyssey/game'
|
||||
import {
|
||||
questSchema,
|
||||
globalExceptionSchema,
|
||||
IQuest,
|
||||
} from '../../../packages/game'
|
||||
import logger from '../utils/logger.js'
|
||||
|
||||
class QuestValidationError extends Error {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { HydratedDocument } from 'mongoose'
|
||||
import { Session, UserProfile } from '@linux-odyssey/models'
|
||||
import type { ISession, IUser } from '@linux-odyssey/models'
|
||||
import { Session, UserProfile } from '../../../packages/models'
|
||||
import type { ISession, IUser } from '../../../packages/models'
|
||||
import { createContainer, deleteContainer } from '../containers/docker.js'
|
||||
import logger from '../utils/logger.js'
|
||||
import { questManager } from './quest.js'
|
||||
@@ -113,7 +113,7 @@ export async function isQuestUnlocked(
|
||||
if (!quest.requirements) {
|
||||
return true
|
||||
}
|
||||
return quest.requirements.every((requiredQuestId) => {
|
||||
return quest.requirements.every((requiredQuestId: string) => {
|
||||
const progress = userProfile.progress.get(requiredQuestId)
|
||||
return progress && progress.completed
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Express } from 'express'
|
||||
import { format } from 'date-fns'
|
||||
import { User, UserProfile } from '@linux-odyssey/models'
|
||||
import { User, UserProfile } from '../../../packages/models'
|
||||
import { hashPassword } from '../utils/auth.js'
|
||||
|
||||
export async function createUser(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { TRPCError } from '@trpc/server'
|
||||
import { ISession, Session } from '@linux-odyssey/models'
|
||||
import { GameSession, VoidFileExistenceChecker } from '@linux-odyssey/game'
|
||||
import { ISession, Session } from '../../../packages/models'
|
||||
import { GameSession, VoidFileExistenceChecker } from '../../../packages/game'
|
||||
import { z } from 'zod'
|
||||
import { createNewSession, isQuestUnlocked } from '../models/sessionManager.js'
|
||||
import config from '../config.js'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { UserProfile } from '@linux-odyssey/models'
|
||||
import { UserProfile } from '../../../packages/models'
|
||||
import { TRPCError } from '@trpc/server'
|
||||
import { protectedProcedure, router } from '../trpc.js'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { User } from '@linux-odyssey/models'
|
||||
import { User } from '../../../packages/models'
|
||||
import config from '../config.js'
|
||||
import { createUser } from '../models/userManager.js'
|
||||
import logger from './logger.js'
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true,
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "src/*.test.js", "dist"],
|
||||
"references": [
|
||||
{ "path": "../packages/constants" },
|
||||
{ "path": "../packages/file-graph" },
|
||||
{ "path": "../packages/models" },
|
||||
{ "path": "../packages/utils" }
|
||||
],
|
||||
"ts-node": {
|
||||
"swc": true
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user