From 30ae6e09532cf73ffddfb6d51ca6acb06fe63c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A7=89?= Date: Sat, 20 Apr 2024 20:27:44 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=97=A0=E7=94=A8=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 ++- collection.js | 21 ----------- kana.js | 29 --------------- main.js | 93 ---------------------------------------------- plugins/comment.js | 15 -------- plugins/image.js | 7 ---- sdk.js | 18 --------- usertools.js | 14 ------- 8 files changed, 3 insertions(+), 199 deletions(-) delete mode 100644 collection.js delete mode 100644 kana.js delete mode 100644 main.js delete mode 100644 plugins/comment.js delete mode 100644 plugins/image.js delete mode 100644 sdk.js delete mode 100644 usertools.js diff --git a/README.md b/README.md index 5347643..0a230d6 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,9 @@ pm2 start node --name kana -- index RESTful 风格 API, url 形式为两段 name是对象类型, _id是对象id. (与 vue 的 router 类同) -如发表一篇文章, 文章类型是 article, 文章 id 是 2333, 则 url为 `/article/2333` - +你可以自定义任何新的对象(路径) +如发布一篇文章, 对象类型是 article, 文章 id 是 2333, 则 url为 `/article/2333` +如发布一条问卷, 对象类型是 questionnaire, 问卷 id 是 1212, 则 url为 `/questionnaire/2333` diff --git a/collection.js b/collection.js deleted file mode 100644 index 848191e..0000000 --- a/collection.js +++ /dev/null @@ -1,21 +0,0 @@ -import https from 'https' - -export default function (url) { - if (!this.item.link) return false; - - var reg = /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/; - if (!reg.test(url)) url = "https://" + url; - - https.get(url, resp => { - let data = '' - resp.on('data', chunk => data += chunk) - resp.on('end', () => { - console.log(JSON.parse(data).explanation) - }) - }).on('error', err => { - console.log(err.message) - }) - //this.$axios.get(this.item.link).then((res) => { - // console.log(res.data); - //}); -} \ No newline at end of file diff --git a/kana.js b/kana.js deleted file mode 100644 index d9489e7..0000000 --- a/kana.js +++ /dev/null @@ -1,29 +0,0 @@ -import nedb from 'nedb' - -const databases = new Map() -const db = (name) => (databases.get(name) || function () { - let database = new nedb({ filename: `./data/db/${name}.db`, autoload: true, timestampData: true }) - databases.set(name, database) - return database -}()) - - -export default { - list: (name, query, callback) => { - db(name).find(query, callback) - }, - item: (name) => { }, - user: {}, - account: { - create: (data) => { }, - delete: (data) => { }, - }, - session: { - create: (data) => { }, - delete: (data) => { }, - }, - message: { - create: (data) => { }, - delete: (data) => { }, - }, -} diff --git a/main.js b/main.js deleted file mode 100644 index 53c4eaa..0000000 --- a/main.js +++ /dev/null @@ -1,93 +0,0 @@ -import express from 'express' -import expressWs from 'express-ws' -import session from 'express-session' -import sessionDb from 'express-session-nedb' -import kana from './kana.js' - -const app = expressWs(express()).app -app.use(express.json()) -app.use(express.urlencoded({ extended: false })) -app.use(session({ secret: 'kana', name: 'sid', resave: false, saveUninitialized: false, cookie: { maxAge: 180 * 24 * 3600000 }, store: session_store })) -app.use('/data/file/', express.static('data/file')) -app.ws('/', websocketer) - - - -function listFind(req, res) { - // 通过权限判断不可使用的字段 -} - - -app.route('/:list').get(kana.list.find) - -//import kana from 'kana' -// -//// 初始化一个 -////const app = new kana() -// -//// list 是对象集合模型, 它规划了对象集合的生命周期, 因此也在此处配置 -////kana.list.set -// -//// 使用 list 初始化指定类型的对象, 以对其进行特殊意义的操作 -//const list = new kana.list("name") -// -// -//// item 是对象模型, 它规划了对象模型的生命周期 -//const item = new kana.item("name") -// -// -//// 点赞一个对象 -//// 取消点赞 -// -//// fm 是频道通道, -////const fm -// -// -// -// -//// 开始使用 -//// 1. like 事件对模型节点挂载 -//// 1. 需要 -// -//like.config({ -// set: "点赞时", -// del: "取消时", -//}) -// -// -//// 列表执行过程中调用 -//list.config({ -// create: (item) => { -// // 通知关注作者的用户 -// message.create({ -// // 构成消息结构 -// }) -// }, -// remove: "移除时执行", -//}) -// -//// 或向列表执行过程中注入? -//// 函数式要求无状态 -//// HAS -// -//const create = kana.list.create(item => { -// // 创建对象时, 触发的所有事件 -//}) -// -//const remove = kana.list.delete(item => { -// // 移除对象时, 触发的所有事件 -//}) -// -//kana.run({ -// // 如果触发结果 -//}) -// -// -//// 创建对象时发生什么 -//// 1. 记录日志 -//// 2. 通知关注者 -//// -//// 消息或日志挂载到哪里 -//// 1. 创建对象时(通知的信息不同) -//// 2. 删除对象时(记录的信息不同) -//// diff --git a/plugins/comment.js b/plugins/comment.js deleted file mode 100644 index 523cfe3..0000000 --- a/plugins/comment.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * 博客评论插件 - */ - -export default class { - constructor() { - // 初始化 - } - - // 发表一条评论 - // 获取某个主题的评论列表时, 隐藏未经审核的 SID - // 在本地生成一个会话sid(非时间种子随机码), 发送评论时附上, 以及邮箱 - // 则服务端对相同的会话sid(已审核的)直接放行显示 - // 否则不放行 -} diff --git a/plugins/image.js b/plugins/image.js deleted file mode 100644 index e693d0e..0000000 --- a/plugins/image.js +++ /dev/null @@ -1,7 +0,0 @@ -export default { - // 任意用户上传图像, 但仅被缓存一段时间 - - // 当提交引用不存在的图像时, 移除引用 - // 当提交引用已被引用的图像时, 增加引用计数 - -} \ No newline at end of file diff --git a/sdk.js b/sdk.js deleted file mode 100644 index 94c8fda..0000000 --- a/sdk.js +++ /dev/null @@ -1,18 +0,0 @@ -export default class { - constructor() { - // 初始化状态, 连接, 确认登录状态 - this.title = "Kana" - this.info = "站点信息" - this.account = 'account' - } - // 对像的增删改查 -} - -class account { - constructor() { - this.name = "Last" - this.avatar = "xxxxxx" - this.createdAt = "是创建时间" - this.createdAt_fmt = "是格式化时间, 有很多格式" - } -} diff --git a/usertools.js b/usertools.js deleted file mode 100644 index 26373d1..0000000 --- a/usertools.js +++ /dev/null @@ -1,14 +0,0 @@ -export default { - 用户信息隐私保护(user) { - delete user.password - delete user.salt - delete user.mobile - delete user.email - return user - }, - 用户信息密码保护(user) { - delete user.password - delete user.salt - return user - } -} \ No newline at end of file