ui: support @[user]()

This commit is contained in:
undefined committed 2021-05-19 23:12:07 +08:00
1 parent b272598685
commit c5b2552f59
8 files changed
+47 -12

No files matched your search

@@ -0,0 +1,15 @@
import { AutoloadPage } from 'vj/misc/Page';
import request from 'vj/utils/request';
export default new AutoloadPage('media', async () => {
const items = [];
const resolvers = [];
const users = $('div[data-user]');
users.get().forEach((ele) => {
items.push({ type: 'user', id: $(ele).text() });
resolvers.push((html) => $(ele).replaceWith($(html)));
});
if (!items.length) return;
const res = await request.post('/media', { items });
for (let i = 0; i < res.length; i++) resolvers[i](res[i]);
});
@@ -1,14 +1,14 @@
.user-profile-avatar .user-profile-avatar
border-radius: 50% border-radius: 50% !important
.user-profile-badge .user-profile-badge
display: inline-block display: inline-block !important
font-size: rem(12px) font-size: rem(12px) !important
padding: rem(3px 4px) padding: rem(3px 4px) !important
line-height: 1 line-height: 1 !important
&:hover &:hover
text-decoration: none text-decoration: none !important
for n in (1..21) for n in (1..21)
.user-profile-bg--{n} .user-profile-bg--{n}
+19
View File
@@ -132,6 +132,24 @@ class MarkdownHandler extends Handler {
} }
} }
class RichMediaHandler extends Handler {
constructor(args) {
super(args);
this.noCheckPermView = true;
}
async post({ domainId, items }) {
const res = [];
for (const item of items) {
if (item.type === 'user') {
const udoc = Number.isNaN(+item.id) ? await user.getByUname(domainId, item.id) : await user.getById(domainId, +item.id);
res.push(this.renderHTML('partials/user.html', { udoc }));
} else res.push('');
}
this.response.body = await Promise.all(res);
}
}
const getHash = (i) => { const getHash = (i) => {
const shasum = crypto.createHash('sha1'); const shasum = crypto.createHash('sha1');
const file = readFileSync(join(tmpdir(), 'hydro', 'public', i)); const file = readFileSync(join(tmpdir(), 'hydro', 'public', i));
@@ -160,4 +178,5 @@ global.Hydro.handler.ui = async () => {
Route('set_theme', '/set_theme/:id', SetThemeHandler); Route('set_theme', '/set_theme/:id', SetThemeHandler);
Route('ui_extracss', '/extra.css', UiSettingsHandler); Route('ui_extracss', '/extra.css', UiSettingsHandler);
Route('markdown', '/markdown', MarkdownHandler); Route('markdown', '/markdown', MarkdownHandler);
Route('media', '/media', RichMediaHandler);
}; };
+1
View File
@@ -251,6 +251,7 @@ small, figcaption
.typo a, .typo .link, .typo-a .typo a, .typo .link, .typo-a
&, &:visited, &:active, &:hover &, &:visited, &:active, &:hover
:not(.user-profile-name)
color: $primary-color color: $primary-color
.typo p, .typo dl, .typo form, .typo hr, .typo table .typo p, .typo dl, .typo form, .typo hr, .typo table
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/ui-default", "name": "@hydrooj/ui-default",
"version": "4.8.30", "version": "4.8.31",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "hydro.js", "main": "hydro.js",
@@ -5,7 +5,7 @@
<img class="small user-profile-avatar v-center" src="{{ avatarUrl(udoc.avatar|default('')) }}" width="20" height="20"> <img class="small user-profile-avatar v-center" src="{{ avatarUrl(udoc.avatar|default('')) }}" width="20" height="20">
{% endif %} {% endif %}
<a class="user-profile-name" href="{{ url('user_detail', uid=udoc._id) }}"> <a class="user-profile-name" href="{{ url('user_detail', uid=udoc._id) }}">
{% if udoc.displayName %} {% if udoc.displayName and udoc.displayName != udoc.uname %}
{{ udoc.displayName }} ({{ udoc.uname }}) {{ udoc.displayName }} ({{ udoc.uname }})
{% else %} {% else %}
{{ udoc.uname }} {{ udoc.uname }}
@@ -0,0 +1,2 @@
{% import "components/user.html" as user with context %}
{{ user.render_inline(udoc) }}
+2 -4
View File
@@ -73,10 +73,8 @@ const request = {
postData = dataOrForm; postData = dataOrForm;
} else { } else {
// {foo: 'bar'} // {foo: 'bar'}
postData = $.param({ postData = JSON.stringify(dataOrForm);
csrfToken: UiContext.csrfToken, options.contentType = 'application/json';
...dataOrForm,
}, true);
} }
return request.ajax({ return request.ajax({
url, url,