不知道喵
This commit is contained in:
35
server/Types.js
Normal file
35
server/Types.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
export class TheWhiteSilkParams {
|
||||||
|
/**
|
||||||
|
* @type { String }
|
||||||
|
*/
|
||||||
|
method
|
||||||
|
/**
|
||||||
|
* @type { Object }
|
||||||
|
*/
|
||||||
|
args
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CallbackMessage {
|
||||||
|
static Code = class {
|
||||||
|
/**
|
||||||
|
* 无权限
|
||||||
|
*/
|
||||||
|
static PERMISSION_DENIED = 4
|
||||||
|
/**
|
||||||
|
* 服务端错误
|
||||||
|
*/
|
||||||
|
static SERVER_ERROR = 5
|
||||||
|
/**
|
||||||
|
* 请求成功
|
||||||
|
*/
|
||||||
|
static OK = 2
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @type { String }
|
||||||
|
*/
|
||||||
|
msg
|
||||||
|
/**
|
||||||
|
* @type { Number }
|
||||||
|
*/
|
||||||
|
code
|
||||||
|
}
|
||||||
@@ -1,24 +1,31 @@
|
|||||||
class UserManager {
|
import io from '../lib/io.js';
|
||||||
static findUserById(id) {
|
|
||||||
|
|
||||||
|
const baseDir = 'whiteslik_data/user'
|
||||||
|
|
||||||
|
export class UserManager {
|
||||||
|
static getUserProfileDir(id) {
|
||||||
|
return `${baseDir}/${id}`
|
||||||
|
}
|
||||||
|
static findUserById(id) {
|
||||||
|
let list = io.listFolders(baseDir)
|
||||||
|
console.log(list)
|
||||||
}
|
}
|
||||||
static findUserByName(name) {
|
static findUserByName(name) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建新用户
|
* 创建新用户
|
||||||
* @param { Object } arg
|
* @param { Object } arg
|
||||||
* @param { String } [arg.name] 用户名
|
* @param { String } [arg.name] 用户名
|
||||||
* @param { String } [arg.name] 用户名
|
|
||||||
* @returns { User }
|
* @returns { User }
|
||||||
*/
|
*/
|
||||||
static createUser() {
|
static createUser({ name } = {}) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class User {
|
export class User {
|
||||||
/** @type { Number } */
|
/** @type { Number } */
|
||||||
id
|
id
|
||||||
/** @type { String } */
|
/** @type { String } */
|
||||||
@@ -29,14 +36,8 @@ class User {
|
|||||||
description
|
description
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserApi {
|
export class UserApi {
|
||||||
static createUser() {
|
static createUser() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
|
||||||
User,
|
|
||||||
UserManager,
|
|
||||||
UserApi
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import fs from 'node:fs'
|
|||||||
/**
|
/**
|
||||||
* 简单文件类
|
* 简单文件类
|
||||||
*/
|
*/
|
||||||
class io {
|
export default class io {
|
||||||
/**
|
/**
|
||||||
* 构建函数
|
* 构建函数
|
||||||
* @param { String } path
|
* @param { String } path
|
||||||
@@ -44,7 +44,7 @@ class io {
|
|||||||
* @param { Boolean } 是否搜索文件夹内的文件
|
* @param { Boolean } 是否搜索文件夹内的文件
|
||||||
* @returns { String[] } 文件完整路径列表
|
* @returns { String[] } 文件完整路径列表
|
||||||
*/
|
*/
|
||||||
static listFiles(path, filter, recursive) {
|
static listFiles(path, { filter, recursive } = {}) {
|
||||||
let a = fs.readdirSync(path, { recursive: recursive })
|
let a = fs.readdirSync(path, { recursive: recursive })
|
||||||
a.forEach(function(v, index, arrayThis) {
|
a.forEach(function(v, index, arrayThis) {
|
||||||
arrayThis[index] = `${path}//${v}`
|
arrayThis[index] = `${path}//${v}`
|
||||||
@@ -59,11 +59,12 @@ class io {
|
|||||||
/**
|
/**
|
||||||
* 枚举目录下所有文件夹
|
* 枚举目录下所有文件夹
|
||||||
* @param { String } 扫描路径
|
* @param { String } 扫描路径
|
||||||
* @param { Function<String> } 过滤器<文件夹完整路径>
|
* @param { Object } 额外参数
|
||||||
* @param { Boolean } 是否搜索文件夹内的文件夹
|
* @param { Function<String> } [filter] 额外参数.过滤器<文件夹完整路径>
|
||||||
|
* @param { Boolean } [recursive] 额外参数.是否搜索文件夹内的文件夹
|
||||||
* @returns { String[] } 文件夹完整路径列表
|
* @returns { String[] } 文件夹完整路径列表
|
||||||
*/
|
*/
|
||||||
static listFolders(path, filter, recursive) {
|
static listFolders(path, { filter, recursive } = {}) {
|
||||||
let a = fs.readdirSync(path, { recursive: recursive })
|
let a = fs.readdirSync(path, { recursive: recursive })
|
||||||
a.forEach(function(v, index, arrayThis) {
|
a.forEach(function(v, index, arrayThis) {
|
||||||
arrayThis[index] = `${path}//${v}`
|
arrayThis[index] = `${path}//${v}`
|
||||||
@@ -245,5 +246,3 @@ class io {
|
|||||||
delete this.w
|
delete this.w
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default io
|
|
||||||
|
|||||||
@@ -3,41 +3,33 @@ import http from 'node:http'
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
import { Server as SocketIoServer } from 'socket.io'
|
import { Server as SocketIoServer } from 'socket.io'
|
||||||
|
|
||||||
|
// 类型提示
|
||||||
|
import { TheWhiteSilkParams, CallbackMessage } from './Types.js'
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
const httpApp = http.createServer(app)
|
const httpApp = http.createServer(app)
|
||||||
const io = new SocketIoServer(httpApp, {})
|
const io = new SocketIoServer(httpApp, {})
|
||||||
|
|
||||||
class ThewhiteSilkParams {
|
const events = {}
|
||||||
/**
|
|
||||||
* @type { String }
|
|
||||||
*/
|
|
||||||
method
|
|
||||||
/**
|
|
||||||
* @type { Object }
|
|
||||||
*/
|
|
||||||
args
|
|
||||||
}
|
|
||||||
|
|
||||||
const events = []
|
|
||||||
import { UserApi } from './api/User.js'
|
import { UserApi } from './api/User.js'
|
||||||
|
|
||||||
for (let i of [
|
for (let i of [
|
||||||
UserApi
|
UserApi,
|
||||||
]) {
|
]) {
|
||||||
for (let i2 of Object.keys(i)) {
|
for (let i2 of Object.keys(i)) {
|
||||||
events.push(i[i2])
|
events[i2] = i[i2]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
io.on("connection", (socket) => {
|
io.on("connection", (socket) => {
|
||||||
socket.on('the_white_silk',
|
socket.on('the_white_silk',
|
||||||
/**
|
/**
|
||||||
* @param { ThewhiteSilkParams } params
|
* @param { TheWhiteSilkParams } params
|
||||||
* @param { Function } callback
|
* @param { Function<> } callback
|
||||||
*/
|
*/
|
||||||
(params, callback) => {
|
(params, callback) => {
|
||||||
if ((params || callback) == null) return;
|
if ((params || callback) == null || typeof callback != Function) return;
|
||||||
|
(events[params.method] || (() => callback({mess})))(params.args)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user