remove html2md

This commit is contained in:
undefined committed 2020-09-11 13:40:44 +08:00
1 parent 9e225f5daa
commit f723e2815f
11 files changed
+60 -109

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@
"pub": "node build/publish", "pub": "node build/publish",
"jest": "node build/jest", "jest": "node build/jest",
"start": "node --async-stack-traces --trace-deprecation --enable-source-maps build/start", "start": "node --async-stack-traces --trace-deprecation --enable-source-maps build/start",
"clean": "zsh -c \"rm -r tsconfig.build.tsbuildinfo ./packages/*/tsconfig.tsbuildinfo ./packages/*/dist ./coverage\"" "clean": "zsh -c \"rm -r tsconfig.build.tsbuildinfo ./packages/*/tsconfig.tsbuildinfo ./packages/*/dist ./.coverage\""
}, },
"version": "1.0.0", "version": "1.0.0",
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
-20
View File
@@ -1,20 +0,0 @@
import 'hydrooj';
import TurndownService from 'turndown';
declare module 'hydrooj' {
interface Lib {
convertHTML: (str: string) => string,
}
}
const turndownService = new TurndownService({
headingStyle: 'atx',
codeBlockStyle: 'fenced',
bulletListMarker: '-',
});
export function convertHTML(html: string) {
return turndownService.turndown(html);
}
global.Hydro.lib.convertHTML = convertHTML;
-23
View File
@@ -1,23 +0,0 @@
{
"name": "@hydrooj/html2md",
"version": "1.0.2",
"description": "turn html into markdown",
"main": "lib.js",
"typings": "lib.d.ts",
"repository": "https://github.com/hydro-dev/Hydro.git",
"author": "undefined <masnn0@outlook.com>",
"license": "AGPL-3.0-only",
"dependencies": {
"turndown": "^6.0.0"
},
"devDependencies": {
"@types/turndown": "^5.0.0"
},
"peerDependencies": {
"hydrooj": "^2.12.22"
},
"scripts": {
"build": "tsc",
"lint": "eslint . --ext ts --fix"
}
}
-8
View File
@@ -1,8 +0,0 @@
import 'hydrooj';
import { convertHTML } from '@hydrooj/html2md/lib';
describe('html2md', () => {
test('convertHTML', () => {
expect(convertHTML('<h1>Test</h1><p>test</p>')).toStrictEqual('# Test\n\ntest');
});
});
-19
View File
@@ -1,19 +0,0 @@
{
"compilerOptions": {
"target": "es2019",
"module": "commonjs",
"esModuleInterop": true,
"moduleResolution": "node",
"declaration": true,
"sourceMap": true,
"composite": true,
"strictBindCallApply": true,
"experimentalDecorators": true,
"outDir": ".",
"rootDir": "."
},
"include": [
"*.ts"
],
"exclude": []
}
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.13.9", "version": "2.13.10",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "dist/loader.js", "main": "dist/loader.js",
"typings": "dist/loader.d.ts", "typings": "dist/loader.d.ts",
+1 -1
View File
@@ -43,7 +43,7 @@ const checks: Dictionary<CheckItem> = {
}, },
}; };
export async function start(ctx, log, warn, error, cb: (id: string) => any) { export async function start(ctx, log, warn, error, cb: (id: string) => void) {
const id = String.random(6); const id = String.random(6);
cb(id); cb(id);
for (const name in checks) { for (const name in checks) {
+14 -3
View File
@@ -5,6 +5,10 @@ import { Dictionary, NumericDictionary } from 'lodash';
export type NumberKeys<O> = { export type NumberKeys<O> = {
[K in keyof O]: number extends O[K] ? K : never [K in keyof O]: number extends O[K] ? K : never
}[keyof O];
export type ArrayKeys<O, P = any> = {
[K in keyof O]: P[] extends O[K] ? K : never
}[keyof O] }[keyof O]
export interface System { export interface System {
@@ -157,7 +161,7 @@ export type ProblemConfig = LocalProblemConfig | RemoteProblemConfig;
export interface Pdoc { export interface Pdoc {
_id: ObjectID, _id: ObjectID,
domainId: string, domainId: string,
docType: number, docType: 10,
docId: number, docId: number,
pid: string, pid: string,
owner: number, owner: number,
@@ -181,14 +185,21 @@ export interface Pdoc {
export type Pdict = NumericDictionary<Pdoc>; export type Pdict = NumericDictionary<Pdoc>;
export interface ProblemStatusDoc { export interface StatusDoc {
_id: ObjectID, _id: ObjectID,
docId: number, docId: any,
docType: number, docType: number,
domainId: string, domainId: string,
uid: number, uid: number,
}
export interface ProblemStatusDoc extends StatusDoc {
docId: number,
docType: 10,
rid?: ObjectID, rid?: ObjectID,
status?: number, status?: number,
nSubmit?: number,
nAccept?: number,
star?: boolean, star?: boolean,
} }
+1 -3
View File
@@ -1,9 +1,7 @@
import { Collection } from 'mongodb';
import * as db from '../service/db'; import * as db from '../service/db';
import * as bus from '../service/bus'; import * as bus from '../service/bus';
import { Bdoc } from '../interface';
const coll: Collection<Bdoc> = db.collection('blacklist'); const coll = db.collection('blacklist');
export async function add(ip: string) { export async function add(ip: string) {
/** /**
+42 -29
View File
@@ -1,9 +1,11 @@
import assert from 'assert'; import assert from 'assert';
import { ObjectID, Cursor, FilterQuery } from 'mongodb'; import {
ObjectID, Cursor, FilterQuery, UpdateQuery,
} from 'mongodb';
import * as db from '../service/db'; import * as db from '../service/db';
import * as bus from '../service/bus'; import * as bus from '../service/bus';
import { import {
Pdoc, Ddoc, Ufdoc, Drdoc, Tdoc, TrainingDoc, NumberKeys, Pdoc, Ddoc, Ufdoc, Drdoc, Tdoc, TrainingDoc, NumberKeys, ArrayKeys, ProblemStatusDoc,
} from '../interface'; } from '../interface';
type DocID = ObjectID | string | number; type DocID = ObjectID | string | number;
@@ -35,6 +37,11 @@ export interface DocType {
[TYPE_HOMEWORK]: Tdoc, [TYPE_HOMEWORK]: Tdoc,
} }
export interface DocStatusType {
[TYPE_PROBLEM]: ProblemStatusDoc,
[key: number]: any
}
export async function add<T extends DocID, K extends keyof DocType>( export async function add<T extends DocID, K extends keyof DocType>(
domainId: string, content: string, owner: number, domainId: string, content: string, owner: number,
docType: K, docId: DocType[K]['docId'], docType: K, docId: DocType[K]['docId'],
@@ -104,8 +111,8 @@ export function deleteMulti<K extends keyof DocType>(
return coll.deleteMany({ ...query, domainId, docType }); return coll.deleteMany({ ...query, domainId, docType });
} }
export function deleteMultiStatus<K extends keyof DocType>( export function deleteMultiStatus<K extends keyof DocStatusType>(
domainId: string, docType: K, query?: FilterQuery<DocType[K]>, domainId: string, docType: K, query?: FilterQuery<DocStatusType[K]>,
) { ) {
return collStatus.deleteMany({ ...query, domainId, docType }); return collStatus.deleteMany({ ...query, domainId, docType });
} }
@@ -128,8 +135,6 @@ export async function inc<K extends keyof DocType>(
return res.value; return res.value;
} }
type Q = NumberKeys<DocType[10]>
export async function incAndSet<K extends keyof DocType>( export async function incAndSet<K extends keyof DocType>(
domainId: string, docType: K, docId: DocType[K]['docId'], domainId: string, docType: K, docId: DocType[K]['docId'],
key: NumberKeys<DocType[K]>, value: number, args: Partial<DocType[K]>, key: NumberKeys<DocType[K]>, value: number, args: Partial<DocType[K]>,
@@ -169,7 +174,7 @@ export async function push<K extends keyof DocType, T extends keyof DocType[K]>(
export async function pull<K extends keyof DocType>( export async function pull<K extends keyof DocType>(
domainId: string, docType: K, docId: DocType[K]['docId'], domainId: string, docType: K, docId: DocType[K]['docId'],
setKey: string, contents: string[], setKey: ArrayKeys<DocType[K]>, contents: string[],
): Promise<DocType[K]> { ): Promise<DocType[K]> {
const res = await coll.findOneAndUpdate( const res = await coll.findOneAndUpdate(
{ domainId, docType, docId }, { domainId, docType, docId },
@@ -179,10 +184,10 @@ export async function pull<K extends keyof DocType>(
return res.value; return res.value;
} }
export async function deleteSub( export async function deleteSub<K extends keyof DocType>(
domainId: string, docType: number, docId: DocID, domainId: string, docType: K, docId: DocType[K]['docId'],
key: string, subId: ObjectID, key: ArrayKeys<DocType[K]>, subId: ObjectID,
) { ): Promise<DocType[K]> {
const res = await coll.findOneAndUpdate( const res = await coll.findOneAndUpdate(
{ domainId, docType, docId }, { domainId, docType, docId },
{ $pull: { [key]: { _id: subId } } }, { $pull: { [key]: { _id: subId } } },
@@ -191,10 +196,10 @@ export async function deleteSub(
return res.value; return res.value;
} }
export async function getSub( export async function getSub<T extends keyof DocType, K extends ArrayKeys<DocType[T]>>(
domainId: string, docType: number, docId: DocID, domainId: string, docType: T, docId: DocType[T]['docId'],
key: string, subId: ObjectID, key: K, subId: ObjectID,
) { ): Promise<[DocType[T], DocType[T][K]][0]> {
const doc = await coll.findOne({ const doc = await coll.findOne({
domainId, domainId,
docType, docType,
@@ -208,10 +213,10 @@ export async function getSub(
return [doc, null]; return [doc, null];
} }
export async function setSub( export async function setSub<T extends keyof DocType, K extends ArrayKeys<DocType[T]>>(
domainId: string, docType: number, docId: DocID, domainId: string, docType: T, docId: DocType[T]['docId'],
key: string, subId: ObjectID, args: any, key: K, subId: ObjectID, args: UpdateQuery<DocType[T][K][0]>['$set'],
) { ): Promise<DocType[T]> {
const $set = {}; const $set = {};
for (const k in args) { for (const k in args) {
$set[`${key}.$.${k}`] = args[k]; $set[`${key}.$.${k}`] = args[k];
@@ -229,9 +234,9 @@ export async function setSub(
return res.value; return res.value;
} }
export async function addToSet( export async function addToSet<T extends keyof DocType, K extends ArrayKeys<DocType[T], string>>(
domainId: string, docType: number, docId: DocID, domainId: string, docType: T, docId: DocType[T]['docId'],
setKey: string, content: string, setKey: K, content: string,
) { ) {
const res = await coll.findOneAndUpdate( const res = await coll.findOneAndUpdate(
{ domainId, docType, docId }, { domainId, docType, docId },
@@ -241,23 +246,29 @@ export async function addToSet(
return res.value; return res.value;
} }
export function getStatus(domainId: string, docType: number, docId: DocID, uid: number) { export function getStatus<K extends keyof DocStatusType>(
domainId: string, docType: K, docId: DocStatusType[K]['docId'], uid: number,
): Promise<DocStatusType[K]> {
return collStatus.findOne({ return collStatus.findOne({
domainId, docType, docId, uid, domainId, docType, docId, uid,
}); });
} }
export function getMultiStatus(domainId: string, docType: number, args: any) { export function getMultiStatus<K extends keyof DocStatusType>(
domainId: string, docType: K, args: FilterQuery<DocStatusType[K]>,
): Cursor<DocStatusType[K]> {
return collStatus.find({ ...args, docType, domainId }); return collStatus.find({ ...args, docType, domainId });
} }
export function getMultiStatusWithoutDomain(docType: number, args: any) { export function getMultiStatusWithoutDomain<K extends keyof DocStatusType>(
docType: K, args: FilterQuery<DocStatusType[K]>,
): Cursor<DocStatusType[K]> {
return collStatus.find({ ...args, docType }); return collStatus.find({ ...args, docType });
} }
export async function setStatus( export async function setStatus<K extends keyof DocStatusType>(
domainId: string, docType: number, docId: DocID, uid: number, args: any, domainId: string, docType: K, docId: DocStatusType[K]['docId'], uid: number, args: UpdateQuery<DocStatusType[K]>['$set'],
) { ): Promise<DocStatusType[K]> {
const res = await collStatus.findOneAndUpdate( const res = await collStatus.findOneAndUpdate(
{ {
domainId, docType, docId, uid, domainId, docType, docId, uid,
@@ -268,7 +279,9 @@ export async function setStatus(
return res.value; return res.value;
} }
export function setMultiStatus(domainId: string, docType: number, query: any, args: any) { export function setMultiStatus<K extends keyof DocStatusType>(
domainId: string, docType: K, query: FilterQuery<DocStatusType[K]>, args: UpdateQuery<DocStatusType[K]>['$set'],
) {
return collStatus.updateMany( return collStatus.updateMany(
{ domainId, docType, ...query }, { domainId, docType, ...query },
{ $set: args }, { $set: args },
-1
View File
@@ -14,7 +14,6 @@
{ "path": "packages/hydrooj" }, { "path": "packages/hydrooj" },
{ "path": "packages/hydrojudge" }, { "path": "packages/hydrojudge" },
{ "path": "packages/geoip" }, { "path": "packages/geoip" },
{ "path": "packages/html2md" },
{ "path": "packages/better-search" }, { "path": "packages/better-search" },
{ "path": "packages/fps-importer" }, { "path": "packages/fps-importer" },
{ "path": "packages/login-with-github" }, { "path": "packages/login-with-github" },