mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
云剪贴板
This commit is contained in:
1 parent
474f495e0c
commit
00cd747768
5 files changed
+174
No files matched your search
@@ -0,0 +1,42 @@
|
||||
const { Route, Handler } = global.Hydro.service.server;
|
||||
const { PERM_LOGGEDIN } = global.Hydro.permission;
|
||||
const { pastebin } = global.Hydro.model;
|
||||
const { nav } = global.Hydro.lib;
|
||||
|
||||
class PasteShowHandler extends Handler {
|
||||
async get({ docId }) {
|
||||
const doc = await pastebin.get(docId);
|
||||
this.response.body = { doc };
|
||||
this.response.template = 'paste_show.html';
|
||||
}
|
||||
}
|
||||
|
||||
class PasteCreateHandler extends Handler {
|
||||
async prepare() {
|
||||
this.checkPerm(PERM_LOGGEDIN);
|
||||
}
|
||||
|
||||
async get() {
|
||||
this.response.template = 'paste_create.html';
|
||||
}
|
||||
|
||||
async post({
|
||||
language, expire, password, title, content,
|
||||
}) {
|
||||
const docId = await pastebin.add({
|
||||
language, expire, password, owner: this.user._id, title, content,
|
||||
});
|
||||
this.response.body = { docId };
|
||||
this.response.redirect = `/paste/${docId}`;
|
||||
}
|
||||
}
|
||||
|
||||
async function apply() {
|
||||
Route('/paste/create', module.exports.PasteCreateHandler);
|
||||
Route('/paste/:docId', module.exports.PasteShowHandler);
|
||||
nav('/paste/create', 'pastebin', 'pastebin', PERM_LOGGEDIN);
|
||||
}
|
||||
|
||||
global.Hydro.handler.paste = module.exports = {
|
||||
PasteCreateHandler, PasteShowHandler, apply,
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "module-pastebin",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
const { DocumentNotFoundError } = global.Hydro.error;
|
||||
const { db } = global.Hydro.service;
|
||||
|
||||
const coll = db.collection('pastebin');
|
||||
|
||||
async function add({
|
||||
owner, language, expire, password, title, content,
|
||||
}) {
|
||||
const doc = {
|
||||
owner, password, expire, language, title, content,
|
||||
};
|
||||
const res = await coll.insertOne(doc);
|
||||
return res.insertedId;
|
||||
}
|
||||
|
||||
async function get(_id) {
|
||||
const doc = await coll.findOne({ _id });
|
||||
if (!doc) throw new DocumentNotFoundError(_id);
|
||||
return doc;
|
||||
}
|
||||
|
||||
function del(_id) {
|
||||
return coll.deleteOne({ _id });
|
||||
}
|
||||
|
||||
global.Hydro.model.pastebin = module.exports = { add, get, del };
|
||||
@@ -0,0 +1,54 @@
|
||||
{% set page_name = "paste_create" %}
|
||||
{% extends "layout/basic.html" %}
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="medium-9 columns">
|
||||
<div class="section">
|
||||
<div class="section__body">
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="medium-7 columns">
|
||||
<label>
|
||||
{{ _('Title') }}
|
||||
<input name="title" placeholder="{{ _('title') }}" class="textbox" autofocus>
|
||||
</label>
|
||||
</div>
|
||||
<div class="medium-3 columns">
|
||||
<label>
|
||||
{{ _('Language') }}
|
||||
<br>
|
||||
<label>
|
||||
<input name="language" placeholder="{{ _('Language of the content') }}" class="textbox">
|
||||
</label>
|
||||
</label>
|
||||
</div>
|
||||
<div class="medium-2 columns">
|
||||
<label>
|
||||
<br>
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" name="private" value="on">{{ _('Private') }}
|
||||
</label>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row"><div class="columns">
|
||||
<label>
|
||||
{{ _('Content') }}
|
||||
<textarea name="content" class="textbox" data-markdown style="height: 500px"></textarea>
|
||||
</label>
|
||||
</div></div>
|
||||
<div class="row"><div class="columns">
|
||||
<input type="hidden" name="csrfToken" value="{{ handler.csrfToken }}">
|
||||
<button type="submit" class="rounded primary button">
|
||||
{{ _('Create') }}
|
||||
</button>
|
||||
</div></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="medium-3 columns">
|
||||
{% include 'components/md_hint.html' %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,48 @@
|
||||
{% set page_name = "paste_create" %}
|
||||
{% extends "layout/basic.html" %}
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="medium-9 columns">
|
||||
<div class="section">
|
||||
<div class="section__body">
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="medium-7 columns">
|
||||
<label>
|
||||
{{ _('Title') }}
|
||||
<input name="title" value="{{ doc.title }}" class="textbox" autofocus>
|
||||
</label>
|
||||
</div>
|
||||
<div class="medium-3 columns">
|
||||
<label>
|
||||
{{ _('Language') }}
|
||||
<br>
|
||||
<label>
|
||||
<input name="language" value="{{ doc.language }}" class="textbox">
|
||||
</label>
|
||||
</label>
|
||||
</div>
|
||||
<div class="medium-2 columns">
|
||||
<label>
|
||||
<br>
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" name="private" value="on">{{ _('Private') }}
|
||||
</label>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row"><div class="columns">
|
||||
<label>
|
||||
{{ _('Content') }}
|
||||
<textarea name="content" class="textbox" style="height: 500px">{{ doc.content }}</textarea>
|
||||
</label>
|
||||
</div></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="medium-3 columns">
|
||||
{% include 'components/md_hint.html' %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in new issue
Block a user