new services + new scripts
This commit is contained in:
parent
8866784d49
commit
5538a042df
@ -1,15 +1,21 @@
|
||||
import Server, { Services } from './framework/express/server';
|
||||
import Mongo from './framework/mongo/mongo';
|
||||
import Server from './framework/express/server';
|
||||
import ip from 'ip';
|
||||
import UserModel from './framework/mongo/user';
|
||||
import { MongoClient } from 'mongodb';
|
||||
|
||||
const PORT = 8000;
|
||||
const MONGOURI = 'mongodb://localhost:27017';
|
||||
const DBNAME = 'dev';
|
||||
|
||||
const mongo = new Mongo(MONGOURI);
|
||||
export type Services = {
|
||||
userModel: UserModel;
|
||||
};
|
||||
|
||||
const mongo = new MongoClient(MONGOURI);
|
||||
const db = mongo.db(DBNAME);
|
||||
|
||||
const services: Services = {
|
||||
db: mongo.getDb(DBNAME),
|
||||
userModel: new UserModel(db),
|
||||
};
|
||||
|
||||
const server = new Server(services);
|
||||
|
@ -1,4 +1,10 @@
|
||||
import { UserCtor, UserInfo } from '@core';
|
||||
import {
|
||||
UserCtor,
|
||||
UserInfo,
|
||||
UserInfoWithPassword,
|
||||
UserWithPasswordCtor,
|
||||
} from '@core';
|
||||
import { createHash, Hash } from 'crypto';
|
||||
import { Entity } from './entity';
|
||||
|
||||
export class User extends Entity implements UserInfo {
|
||||
@ -12,7 +18,18 @@ export class User extends Entity implements UserInfo {
|
||||
|
||||
Info(): UserInfo {
|
||||
return {
|
||||
uuid: this.uuid,
|
||||
name: this.name,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class UserWithPassword extends User implements UserInfoWithPassword {
|
||||
password: Hash;
|
||||
|
||||
constructor(raw: UserWithPasswordCtor) {
|
||||
super(raw);
|
||||
|
||||
this.password = createHash('sha256').update(`${this.uuid}+${raw.password}`);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Router } from 'express';
|
||||
import { Services } from './server';
|
||||
import { Services } from '../../app';
|
||||
import * as user from './user';
|
||||
|
||||
export function getRoutes(services: Services) {
|
||||
|
@ -2,11 +2,7 @@ import express, { Express } from 'express';
|
||||
import cors from 'cors';
|
||||
import * as router from './router';
|
||||
import { BeforeEach } from './middleware';
|
||||
import { Db } from 'mongodb';
|
||||
|
||||
export type Services = {
|
||||
db: Db;
|
||||
};
|
||||
import { Services } from '../../app';
|
||||
|
||||
class Server {
|
||||
private app: Express;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { RequestHandler, Router } from 'express';
|
||||
import { Services } from '../../app';
|
||||
import { Create } from '../../functions/user';
|
||||
import { getId } from './middleware';
|
||||
import { Services } from './server';
|
||||
|
||||
export function LoginHandler(services: Services): RequestHandler {
|
||||
return async (req, res) => {
|
||||
|
@ -1,15 +0,0 @@
|
||||
import { MongoClient, Db } from 'mongodb';
|
||||
|
||||
class Mongo {
|
||||
private client: MongoClient;
|
||||
|
||||
constructor(uri: string) {
|
||||
this.client = new MongoClient(uri);
|
||||
}
|
||||
|
||||
getDb(dbName: string): Db {
|
||||
return this.client.db(dbName);
|
||||
}
|
||||
}
|
||||
|
||||
export default Mongo;
|
@ -1,28 +1,22 @@
|
||||
import { Collection, Db } from 'mongodb';
|
||||
import { User } from '../../entities/user';
|
||||
import { Services } from '../express/server';
|
||||
|
||||
export function Create(
|
||||
services: Services,
|
||||
): (tracker: string, user: User) => Promise<User> {
|
||||
const { db } = services;
|
||||
const coll = db.collection<User>('users');
|
||||
const readUser = Read(services);
|
||||
class UserModel {
|
||||
private collection: Collection<User>;
|
||||
|
||||
return async (tracker, user) => {
|
||||
await coll.insertOne(user);
|
||||
return readUser(tracker, user.uuid);
|
||||
};
|
||||
}
|
||||
constructor(db: Db) {
|
||||
this.collection = db.collection<User>('users');
|
||||
}
|
||||
|
||||
export function Read(
|
||||
services: Services,
|
||||
): (tracker: string, uuid: string) => Promise<User> {
|
||||
const { db } = services;
|
||||
const coll = db.collection<User>('users');
|
||||
|
||||
return async (tracker, uuid) => {
|
||||
const user = await coll.findOne({ uuid });
|
||||
public async create(tracker: string, user: User) {
|
||||
await this.collection.insertOne(user);
|
||||
return this.read(tracker, user.uuid);
|
||||
}
|
||||
|
||||
public async read(tracker: string, uuid: string) {
|
||||
const user = await this.collection.findOne({ uuid });
|
||||
return new User(user || { name: 'not found' });
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default UserModel;
|
||||
|
@ -1,15 +1,14 @@
|
||||
import { CreateUserBody, UserInfo } from '@core';
|
||||
import { Services } from '../app';
|
||||
import { User } from '../entities/user';
|
||||
import { Services } from '../framework/express/server';
|
||||
import * as mongo from '../framework/mongo/user';
|
||||
|
||||
export function Create(
|
||||
services: Services,
|
||||
): (tracker: string, raw: CreateUserBody) => Promise<UserInfo> {
|
||||
const createUser = mongo.Create(services);
|
||||
const { userModel } = services;
|
||||
|
||||
return async (tracker, raw) => {
|
||||
const user = await createUser(tracker, new User(raw));
|
||||
const user = await userModel.create(tracker, new User(raw));
|
||||
return user.Info();
|
||||
};
|
||||
}
|
||||
|
8
build.py
8
build.py
@ -1,8 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
import os
|
||||
|
||||
for dir in os.listdir('.'):
|
||||
if os.path.isdir(dir) and not dir.startswith('.'):
|
||||
os.chdir(dir)
|
||||
os.system('npm run build')
|
||||
os.chdir('..')
|
13
core/package-lock.json
generated
13
core/package-lock.json
generated
@ -8,10 +8,17 @@
|
||||
"name": "core",
|
||||
"version": "1.0.0",
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.8.4",
|
||||
"prettier": "^2.7.1",
|
||||
"typescript": "^4.8.3"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "18.8.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.8.4.tgz",
|
||||
"integrity": "sha512-WdlVphvfR/GJCLEMbNA8lJ0lhFNBj4SW3O+O5/cEGw9oYrv0al9zTwuQsq+myDUXgNx2jgBynoVgZ2MMJ6pbow==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz",
|
||||
@ -42,6 +49,12 @@
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": {
|
||||
"version": "18.8.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.8.4.tgz",
|
||||
"integrity": "sha512-WdlVphvfR/GJCLEMbNA8lJ0lhFNBj4SW3O+O5/cEGw9oYrv0al9zTwuQsq+myDUXgNx2jgBynoVgZ2MMJ6pbow==",
|
||||
"dev": true
|
||||
},
|
||||
"prettier": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz",
|
||||
|
@ -9,6 +9,7 @@
|
||||
"prettier": "prettier -w ./src"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.8.4",
|
||||
"prettier": "^2.7.1",
|
||||
"typescript": "^4.8.3"
|
||||
}
|
||||
|
@ -1,11 +1,19 @@
|
||||
import { EntityInfo } from './entity';
|
||||
import { Hash } from 'crypto';
|
||||
|
||||
export type UserInfo = {
|
||||
uuid: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type UserInfoWithPassword = {
|
||||
password: Hash;
|
||||
} & UserInfo;
|
||||
|
||||
export type User = UserInfo & EntityInfo;
|
||||
|
||||
export type UserWithPassword = UserInfoWithPassword & EntityInfo;
|
||||
|
||||
export type CreateUserBody = {
|
||||
name: string;
|
||||
password: string;
|
||||
@ -14,3 +22,7 @@ export type CreateUserBody = {
|
||||
export type LoginUserBody = CreateUserBody;
|
||||
|
||||
export type UserCtor = Partial<User>;
|
||||
|
||||
export type UserWithPasswordCtor = {
|
||||
password: string;
|
||||
} & Partial<Omit<UserWithPassword, 'password'>>;
|
||||
|
@ -1,8 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
import os
|
||||
|
||||
for dir in os.listdir('.'):
|
||||
if os.path.isdir(dir) and not dir.startswith('.'):
|
||||
os.chdir(dir)
|
||||
os.system('npm ci')
|
||||
os.chdir('..')
|
@ -1,8 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
import os
|
||||
|
||||
for dir in os.listdir('.'):
|
||||
if os.path.isdir(dir) and not dir.startswith('.'):
|
||||
os.chdir(dir)
|
||||
os.system('npm run prettier')
|
||||
os.chdir('..')
|
12
scripts/build.py
Executable file
12
scripts/build.py
Executable file
@ -0,0 +1,12 @@
|
||||
#!/usr/bin/python
|
||||
import os
|
||||
import json
|
||||
|
||||
apps = json.load(open('apps.json'))['apps']
|
||||
|
||||
print(len(apps), 'apps:', apps)
|
||||
|
||||
for app in apps:
|
||||
os.chdir(app)
|
||||
os.system('npm run build')
|
||||
os.chdir('..')
|
@ -2,8 +2,8 @@
|
||||
|
||||
useradd node -md /home/node -s /usr/sbin/nologin
|
||||
|
||||
python3 install.py
|
||||
python3 build.py
|
||||
python3 scripts/install.py
|
||||
python3 scripts/build.py
|
||||
|
||||
rm -r /var/www/html/*
|
||||
mv www/public/* /var/www/html
|
12
scripts/install.py
Executable file
12
scripts/install.py
Executable file
@ -0,0 +1,12 @@
|
||||
#!/usr/bin/python
|
||||
import os
|
||||
import json
|
||||
|
||||
apps = json.load(open('apps.json'))['apps']
|
||||
|
||||
print(len(apps), 'apps:', apps)
|
||||
|
||||
for app in apps:
|
||||
os.chdir(app)
|
||||
os.system('npm ci')
|
||||
os.chdir('..')
|
12
scripts/prettier.py
Executable file
12
scripts/prettier.py
Executable file
@ -0,0 +1,12 @@
|
||||
#!/usr/bin/python
|
||||
import os
|
||||
import json
|
||||
|
||||
apps = json.load(open('apps.json'))['apps']
|
||||
|
||||
print(len(apps), 'apps:', apps)
|
||||
|
||||
for app in apps:
|
||||
os.chdir(app)
|
||||
os.system('npm run prettier')
|
||||
os.chdir('..')
|
18
www/package-lock.json
generated
18
www/package-lock.json
generated
@ -19,6 +19,7 @@
|
||||
"@tsconfig/svelte": "^2.0.0",
|
||||
"@types/three": "^0.144.0",
|
||||
"prettier": "^2.7.1",
|
||||
"prettier-plugin-svelte": "^2.8.0",
|
||||
"rollup": "^2.3.4",
|
||||
"rollup-plugin-css-only": "^3.1.0",
|
||||
"rollup-plugin-livereload": "^2.0.0",
|
||||
@ -1027,6 +1028,16 @@
|
||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/prettier-plugin-svelte": {
|
||||
"version": "2.8.0",
|
||||
"resolved": "https://registry.npmjs.org/prettier-plugin-svelte/-/prettier-plugin-svelte-2.8.0.tgz",
|
||||
"integrity": "sha512-QlXv/U3bUszks3XYDPsk1fsaQC+fo2lshwKbcbO+lrSVdJ+40mB1BfL8OCAk1W9y4pJxpqO/4gqm6NtF3zNGCw==",
|
||||
"dev": true,
|
||||
"peerDependencies": {
|
||||
"prettier": "^1.16.4 || ^2.0.0",
|
||||
"svelte": "^3.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/queue-microtask": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
|
||||
@ -2381,6 +2392,13 @@
|
||||
"integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==",
|
||||
"dev": true
|
||||
},
|
||||
"prettier-plugin-svelte": {
|
||||
"version": "2.8.0",
|
||||
"resolved": "https://registry.npmjs.org/prettier-plugin-svelte/-/prettier-plugin-svelte-2.8.0.tgz",
|
||||
"integrity": "sha512-QlXv/U3bUszks3XYDPsk1fsaQC+fo2lshwKbcbO+lrSVdJ+40mB1BfL8OCAk1W9y4pJxpqO/4gqm6NtF3zNGCw==",
|
||||
"dev": true,
|
||||
"requires": {}
|
||||
},
|
||||
"queue-microtask": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
|
||||
|
@ -18,6 +18,7 @@
|
||||
"@tsconfig/svelte": "^2.0.0",
|
||||
"@types/three": "^0.144.0",
|
||||
"prettier": "^2.7.1",
|
||||
"prettier-plugin-svelte": "^2.8.0",
|
||||
"rollup": "^2.3.4",
|
||||
"rollup-plugin-css-only": "^3.1.0",
|
||||
"rollup-plugin-livereload": "^2.0.0",
|
||||
|
@ -1,10 +1,10 @@
|
||||
<script lang="ts">
|
||||
// export let name: string;
|
||||
import Test3D from "./components/test3D.svelte";
|
||||
import Test3D from './components/test3D.svelte';
|
||||
</script>
|
||||
|
||||
<main>
|
||||
<Test3D></Test3D>
|
||||
<Test3D />
|
||||
</main>
|
||||
|
||||
<style>
|
||||
|
@ -3,25 +3,38 @@
|
||||
import { beforeUpdate, afterUpdate } from 'svelte';
|
||||
import * as Three from 'three';
|
||||
|
||||
|
||||
let innerWidth: number = 0;
|
||||
let innerHeight: number = 0;
|
||||
|
||||
let scene: Three.Scene = new Three.Scene();
|
||||
let camera: Three.PerspectiveCamera = new Three.PerspectiveCamera(75, innerWidth/innerHeight, 0.1, 1000);
|
||||
let camera: Three.PerspectiveCamera = new Three.PerspectiveCamera(
|
||||
75,
|
||||
innerWidth / innerHeight,
|
||||
0.1,
|
||||
1000,
|
||||
);
|
||||
|
||||
let renderer: Three.WebGLRenderer = new Three.WebGLRenderer();
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
document.body.appendChild(renderer.domElement);
|
||||
|
||||
let box: Three.BoxGeometry = new Three.BoxGeometry(1,1,1);
|
||||
let mat: Three.MeshBasicMaterial = new Three.MeshBasicMaterial({ color: 0x00ff00 });
|
||||
let box: Three.BoxGeometry = new Three.BoxGeometry(1, 1, 1);
|
||||
let mat: Three.MeshBasicMaterial = new Three.MeshBasicMaterial({
|
||||
color: 0x00ff00,
|
||||
});
|
||||
let cube = new Three.Mesh(box, mat);
|
||||
|
||||
scene.add(cube);
|
||||
|
||||
camera.position.z = 5;
|
||||
camera.setViewOffset(window.innerWidth, window.innerHeight, 0, 0, window.innerWidth, window.innerHeight)
|
||||
camera.setViewOffset(
|
||||
window.innerWidth,
|
||||
window.innerHeight,
|
||||
0,
|
||||
0,
|
||||
window.innerWidth,
|
||||
window.innerHeight,
|
||||
);
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
|
||||
function animate() {
|
||||
@ -30,22 +43,26 @@
|
||||
cube.rotation.x += 0.02;
|
||||
cube.rotation.y += 0.02;
|
||||
|
||||
|
||||
renderer.render(scene, camera);
|
||||
};
|
||||
}
|
||||
animate();
|
||||
|
||||
beforeUpdate(() => {
|
||||
|
||||
})
|
||||
beforeUpdate(() => {});
|
||||
|
||||
afterUpdate(() => {
|
||||
camera.setViewOffset(window.innerWidth, window.innerHeight, 0, 0, window.innerWidth, window.innerHeight)
|
||||
camera.setViewOffset(
|
||||
window.innerWidth,
|
||||
window.innerHeight,
|
||||
0,
|
||||
0,
|
||||
window.innerWidth,
|
||||
window.innerHeight,
|
||||
);
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
})
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:window bind:innerWidth bind:innerHeight/>
|
||||
<svelte:window bind:innerWidth bind:innerHeight />
|
||||
|
||||
<style>
|
||||
html,
|
||||
|
Loading…
x
Reference in New Issue
Block a user