不知道喵

This commit is contained in:
MoonLeeeaf
2025-03-16 00:13:51 +08:00
parent 0559f0ecaa
commit cbdf3f093c
4 changed files with 66 additions and 39 deletions

35
server/Types.js Normal file
View 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
}

View File

@@ -1,24 +1,31 @@
class UserManager {
static findUserById(id) {
import io from '../lib/io.js';
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) {
}
/**
* 创建新用户
* @param { Object } arg
* @param { String } [arg.name] 用户名
* @param { String } [arg.name] 用户名
* @returns { User }
*/
static createUser() {
static createUser({ name } = {}) {
}
}
class User {
export class User {
/** @type { Number } */
id
/** @type { String } */
@@ -29,14 +36,8 @@ class User {
description
}
class UserApi {
export class UserApi {
static createUser() {
}
}
export {
User,
UserManager,
UserApi
}

View File

@@ -8,7 +8,7 @@ import fs from 'node:fs'
/**
* 简单文件类
*/
class io {
export default class io {
/**
* 构建函数
* @param { String } path
@@ -44,7 +44,7 @@ class io {
* @param { Boolean } 是否搜索文件夹内的文件
* @returns { String[] } 文件完整路径列表
*/
static listFiles(path, filter, recursive) {
static listFiles(path, { filter, recursive } = {}) {
let a = fs.readdirSync(path, { recursive: recursive })
a.forEach(function(v, index, arrayThis) {
arrayThis[index] = `${path}//${v}`
@@ -59,11 +59,12 @@ class io {
/**
* 枚举目录下所有文件夹
* @param { String } 扫描路径
* @param { Function<String> } 过滤器<文件夹完整路径>
* @param { Boolean } 是否搜索文件夹内的文件夹
* @param { Object } 额外参数
* @param { Function<String> } [filter] 额外参数.过滤器<文件夹完整路径>
* @param { Boolean } [recursive] 额外参数.是否搜索文件夹内的文件夹
* @returns { String[] } 文件夹完整路径列表
*/
static listFolders(path, filter, recursive) {
static listFolders(path, { filter, recursive } = {}) {
let a = fs.readdirSync(path, { recursive: recursive })
a.forEach(function(v, index, arrayThis) {
arrayThis[index] = `${path}//${v}`
@@ -245,5 +246,3 @@ class io {
delete this.w
}
}
export default io

View File

@@ -3,41 +3,33 @@ import http from 'node:http'
import express from 'express'
import { Server as SocketIoServer } from 'socket.io'
// 类型提示
import { TheWhiteSilkParams, CallbackMessage } from './Types.js'
const app = express()
const httpApp = http.createServer(app)
const io = new SocketIoServer(httpApp, {})
class ThewhiteSilkParams {
/**
* @type { String }
*/
method
/**
* @type { Object }
*/
args
}
const events = []
const events = {}
import { UserApi } from './api/User.js'
for (let i of [
UserApi
UserApi,
]) {
for (let i2 of Object.keys(i)) {
events.push(i[i2])
events[i2] = i[i2]
}
}
io.on("connection", (socket) => {
socket.on('the_white_silk',
/**
* @param { ThewhiteSilkParams } params
* @param { Function } callback
* @param { TheWhiteSilkParams } params
* @param { Function<> } callback
*/
(params, callback) => {
if ((params || callback) == null) return;
if ((params || callback) == null || typeof callback != Function) return;
(events[params.method] || (() => callback({mess})))(params.args)
}
)
})