Skip to content

Commit

Permalink
feat(admin,api-server): 导入功能
Browse files Browse the repository at this point in the history
  • Loading branch information
std4453 committed Feb 18, 2024
1 parent e54baff commit 381432c
Show file tree
Hide file tree
Showing 23 changed files with 1,650 additions and 73 deletions.
2 changes: 1 addition & 1 deletion apps/admin/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.codeActionsOnSave": {
"source.fixAll": true
"source.fixAll": "explicit"
},
"yaml.schemas": {
"https://www.graphql-code-generator.com/config.schema.json": "/codegen.yml"
Expand Down
4 changes: 3 additions & 1 deletion apps/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
"oidc-client-ts": "~2.0.5",
"md5": "~2.3.0",
"hsluv": "~0.1.0",
"store2": "~2.14.2"
"store2": "~2.14.2",
"virtualizedtableforantd4": "~1.3.1",
"@lani/parse-torrent-title": "~1.0.0"
},
"files": [
"/dist",
Expand Down
129 changes: 68 additions & 61 deletions apps/admin/src/components/Highlight/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import clsx from 'clsx';
import { escapeRegExp } from 'lodash';
import { useMemo } from 'react';
import styles from './index.module.less';

Expand All @@ -21,78 +22,84 @@ export default function Highlight({
index: number;
length: number;
}
| Array<{
index: number;
length: number;
}>
| undefined
| null);
}) {
const parts = useMemo((): HighlightPart[] => {
if (keyword) {
const index = content.toLowerCase().indexOf(keyword.toLowerCase());
if (index < 0) {
return [{ text: content, highlight: false }];
} else {
return [
{
text: content.substring(0, index),
highlight: false,
},
{
text: content.substring(index, index + keyword.length),
highlight: true,
},
{
text: content.substring(index + keyword.length),
highlight: false,
},
];
}
const matchMap = new Array(content.length).fill(false);

let actualMatch = match;

if (!actualMatch && keyword) {
const keywordParts = keyword.split(' ');

// eslint-disable-next-line @rushstack/security/no-unsafe-regexp
const matchRegExp = new RegExp(
keywordParts.map((part) => escapeRegExp(part)).join('|'),
'ig',
);

actualMatch = matchRegExp;
}
if (match) {
if (match instanceof Function) {
const result = match(content);
if (!result) {
return [{ text: content, highlight: false }];
} else {
const { index, length } = result;
return [
{
text: content.substring(0, index),
highlight: false,
},
{
text: content.substring(index, index + length),
highlight: true,
},
{
text: content.substring(index + length),
highlight: false,
},
];

if (actualMatch instanceof Function) {
const result = actualMatch(content);
if (result && Array.isArray(result)) {
for (const { index, length } of result) {
for (let i = index; i < index + length; i++) {
matchMap[i] = true;
}
}
} else {
const result = content.match(match);
} else if (result) {
const { index, length } = result;
for (let i = index; i < index + length; i++) {
matchMap[i] = true;
}
}
} else if (actualMatch instanceof RegExp) {
const matchAllResult = content.matchAll(actualMatch);

for (const result of matchAllResult) {
const index = result?.index;
const matchLength = result?.[0]?.length;
if (typeof index !== 'number' || !matchLength) {
return [{ text: content, highlight: false }];
} else {
return [
{
text: content.substring(0, index),
highlight: false,
},
{
text: content.substring(index, index + matchLength),
highlight: true,
},
{
text: content.substring(index + matchLength),
highlight: false,
},
];
if (typeof index === 'number' && matchLength) {
for (let i = index; i < index + matchLength; i++) {
matchMap[i] = true;
}
}
}
}
return [{ text: content, highlight: false }];

const result: HighlightPart[] = [];

let lastHighlight = false;
let lastText = '';
for (let i = 0; i < content.length; i++) {
if (matchMap[i] !== lastHighlight) {
if (lastText) {
result.push({
text: lastText,
highlight: lastHighlight,
});
}
lastText = content[i];
lastHighlight = matchMap[i];
} else {
lastText += content[i];
}
}
if (lastText) {
result.push({
text: lastText,
highlight: lastHighlight,
});
}

return result;
}, [content, keyword, match]);

return (
Expand Down

0 comments on commit 381432c

Please sign in to comment.