mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
uiL rich media (problem)
This commit is contained in:
1 parent
a7f364e651
commit
fa5b2e8fee
8 files changed
+51
-16
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.28.38",
|
||||
"version": "2.28.39",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -156,7 +156,7 @@ DomainUserSetting(
|
||||
);
|
||||
|
||||
SystemSetting(
|
||||
Setting('setting_file', 'file.endPoint', null, 'text', 'file.endPoint', 'Storage engine endPoint'),
|
||||
Setting('setting_file', 'file.endPoint', 'http://127.0.0.1:9000', 'text', 'file.endPoint', 'Storage engine endPoint'),
|
||||
Setting('setting_file', 'file.accessKey', null, 'text', 'file.accessKey', 'Storage engine accessKey'),
|
||||
Setting('setting_file', 'file.secretKey', null, 'password', 'file.secretKey', 'Storage engine secret', FLAG_SECRET),
|
||||
Setting('setting_file', 'file.bucket', 'hydro', 'text', 'file.bucket', 'Storage engine bucket'),
|
||||
|
||||
@@ -6,12 +6,33 @@ export default new AutoloadPage('media', async () => {
|
||||
const items = [];
|
||||
const resolvers = [];
|
||||
const users = $dom.find('div[data-user]');
|
||||
users.get().forEach((ele) => {
|
||||
items.push({ type: 'user', id: $(ele).text() });
|
||||
const resolve = (ele, item) => {
|
||||
items.push(item);
|
||||
resolvers.push((html) => $(ele).replaceWith($(html)));
|
||||
};
|
||||
users.get().forEach((ele) => resolve(ele, { type: 'user', id: +$(ele).text() }));
|
||||
$dom.find('.typo').get().forEach((el) => {
|
||||
$(el).find('a[href]').get().forEach((ele) => {
|
||||
let target = $(ele).attr('href');
|
||||
let { domainId } = UiContext;
|
||||
if (target.startsWith(UiContext.url_prefix)) {
|
||||
target.replace(UiContext.url_prefix, '');
|
||||
if (!target.startsWith('/')) target = `/${target}`;
|
||||
}
|
||||
if (!target.startsWith('/') || target.startsWith('//')) return;
|
||||
if (target.startsWith('/d/')) {
|
||||
const [, , domain, ...extra] = target.split('/');
|
||||
domainId = domain;
|
||||
target = `/${extra.join('/')}`;
|
||||
}
|
||||
const [, category, data, extra] = target.split('/');
|
||||
if (!data) return;
|
||||
if (category === 'user' && Number.isInteger(+data) && !extra) resolve(ele, { type: 'user', id: +data });
|
||||
if (category === 'p' && !extra) resolve(ele, { type: 'problem', id: data, domainId });
|
||||
});
|
||||
});
|
||||
if (!items.length) return;
|
||||
const res = await request.post('/media', { items });
|
||||
const res = await request.post(`/d/${UiContext.domainId}/media`, { items });
|
||||
for (let i = 0; i < res.length; i++) resolvers[i](res[i]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
/* eslint-disable no-return-await */
|
||||
/* eslint-disable camelcase */
|
||||
const { readdirSync, readFileSync } = require('fs');
|
||||
const { join } = require('path');
|
||||
const crypto = require('crypto');
|
||||
const { tmpdir } = require('os');
|
||||
const bus = require('hydrooj/dist/service/bus');
|
||||
const { PERM } = require('hydrooj/dist/model/builtin');
|
||||
const markdown = require('./backendlib/markdown');
|
||||
|
||||
const {
|
||||
system, domain, user, setting,
|
||||
system, domain, user, setting, problem,
|
||||
} = global.Hydro.model;
|
||||
const { Route, Handler, UiContextBase } = global.Hydro.service.server;
|
||||
|
||||
@@ -119,18 +121,30 @@ class MarkdownHandler extends Handler {
|
||||
}
|
||||
|
||||
class RichMediaHandler extends Handler {
|
||||
constructor(args) {
|
||||
super(args);
|
||||
this.noCheckPermView = true;
|
||||
async renderUser(domainId, payload) {
|
||||
let d = payload.domainId || domainId;
|
||||
const cur = payload.domainId ? await user.getById(payload.domainId, this.user._id) : this.user;
|
||||
if (!cur.hasPerm(PERM.PERM_VIEW)) d = domainId;
|
||||
const udoc = Number.isNaN(+payload.id) ? await user.getByUname(d, payload.id) : await user.getById(d, +payload.id);
|
||||
return await this.renderHTML('partials/user.html', { udoc });
|
||||
}
|
||||
|
||||
async renderProblem(domainId, payload) {
|
||||
const cur = payload.domainId ? await user.getById(payload.domainId, this.user._id) : this.user;
|
||||
let pdoc = cur.hasPerm(PERM.PERM_VIEW | PERM.PERM_VIEW_PROBLEM)
|
||||
? await problem.get(domainId, payload.data) || problem.default
|
||||
: problem.default;
|
||||
if (pdoc.hidden && !cur.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN)) pdoc = problem.default;
|
||||
return await this.renderHTML('partials/problem.html', { pdoc });
|
||||
}
|
||||
|
||||
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('');
|
||||
if (item.domainId && item.domainId === domainId) delete item.domainId;
|
||||
if (item.type === 'user') res.push(this.renderUser(domainId, item));
|
||||
else if (item.type === 'problem') res.push(this.renderProblem(domainId, item));
|
||||
else res.push('');
|
||||
}
|
||||
this.response.body = await Promise.all(res);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/ui-default",
|
||||
"version": "4.11.25",
|
||||
"version": "4.11.26",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"license": "AGPL-3.0",
|
||||
"main": "hydro.js",
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB |
@@ -17,8 +17,6 @@
|
||||
<link rel="icon" type="image/png" href="{{ static_url('android-chrome-192x192.png') }}" sizes="192x192">
|
||||
<link rel="icon" type="image/png" href="{{ static_url('favicon-96x96.png') }}" sizes="96x96">
|
||||
<link rel="icon" type="image/png" href="{{ static_url('favicon-16x16.png') }}" sizes="16x16">
|
||||
<meta name="msapplication-TileColor" content="#579e9a">
|
||||
<meta name="msapplication-TileImage" content="{{ static_url('mstile-144x144.png') }}">
|
||||
<meta name="theme-color" content="#56758f">
|
||||
{% block ogp %}
|
||||
<meta property="og:site_name" content="{{ model.system.get('server.name') }}" />
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
{% import "components/problem.html" as problem with context %}
|
||||
{{ problem.render_problem_title(pdoc) }}
|
||||
Reference in new issue
Block a user