mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
test1
This commit is contained in:
1 parent
720446b5b4
commit
670b759a98
7 files changed
+114
-30
No files matched your search
@@ -1,10 +1,7 @@
|
||||
const MarkdownIt = require('markdown-it');
|
||||
const katex = require('markdown-it-katex');
|
||||
const Prism = require('prismjs');
|
||||
const loadLanguages = require('prismjs/components/');
|
||||
|
||||
// FIXME doesnt work in webpack
|
||||
loadLanguages(['js', 'javascript', 'go', 'c', 'pascal', 'hs', 'java', 'cs', 'cpp', 'py', 'ruby']);
|
||||
require('prismjs/components/index');
|
||||
|
||||
class Markdown extends MarkdownIt {
|
||||
constructor(safe) {
|
||||
|
||||
@@ -53,6 +53,12 @@ async function addReply(_id, from, content) {
|
||||
return await coll.findOne({ _id }); // eslint-disable-line no-return-await
|
||||
}
|
||||
|
||||
async function send(from, to, content) {
|
||||
const sdoc = await coll.findOne({ $or: [{ from, to }, { from: to, to: from }] });
|
||||
await addReply(sdoc._id, from, content);
|
||||
return sdoc._id;
|
||||
}
|
||||
|
||||
function index() {
|
||||
return Promise.all([
|
||||
coll.createIndex({ to: 1, _id: -1 }),
|
||||
@@ -68,5 +74,6 @@ global.Hydro.model.message = module.exports = {
|
||||
getMany,
|
||||
getMulti,
|
||||
addReply,
|
||||
send,
|
||||
index,
|
||||
};
|
||||
+13
-3
@@ -21,10 +21,20 @@ function del(_id) {
|
||||
|
||||
async function getFirst(query) {
|
||||
const res = await coll.find(query).sort('_id', 1).limit(1).toArray();
|
||||
await coll.deleteOne({ _id: res[0]._id });
|
||||
return res[0];
|
||||
if (res) {
|
||||
await coll.deleteOne({ _id: res[0]._id });
|
||||
return res[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function consume(query, cb) {
|
||||
setInterval(async () => {
|
||||
const res = await getFirst(query);
|
||||
if (res) cb(res);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
add, get, del, count, getFirst,
|
||||
add, get, del, count, getFirst, consume,
|
||||
};
|
||||
Reference in new issue
Block a user