mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 21:14:23 +00:00
Make a demo?
This commit is contained in:
parent
edd8e5b05a
commit
2495911a81
4 changed files with 49 additions and 4 deletions
|
@ -1,6 +1,17 @@
|
|||
async function checkUnsafeContent() {
|
||||
const req = await fetch("/api/contentcheck/kidunfriendlycontent");
|
||||
const res = await req.json();
|
||||
import NewsAnalyzer from "~/components/newsAnalyzer";
|
||||
const newsAnalyzer = new NewsAnalyzer();
|
||||
async function checkUnsafeContent(title: string) {
|
||||
try {
|
||||
const req = await fetch("/api/contentcheck/kidunfriendlycontent");
|
||||
const res = await req.json();
|
||||
const patterns = res.words.map((word) => new RegExp(word, "i"));
|
||||
console.log(patterns);
|
||||
newsAnalyzer.setSensitivePatterns(patterns);
|
||||
const kidfriendly = newsAnalyzer.isKidFriendly(title);
|
||||
return kidfriendly;
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
export default checkUnsafeContent;
|
||||
|
|
20
components/newsAnalyzer.ts
Normal file
20
components/newsAnalyzer.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
// News Analyzer Class
|
||||
class NewsAnalyzer {
|
||||
private sensitivePatterns: RegExp[];
|
||||
constructor() {
|
||||
this.sensitivePatterns = [];
|
||||
}
|
||||
|
||||
isKidFriendly(title) {
|
||||
for (let pattern of this.sensitivePatterns) {
|
||||
if (pattern.test(title)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public setSensitivePatterns(patterns: RegExp[]): void {
|
||||
this.sensitivePatterns = patterns;
|
||||
}
|
||||
}
|
||||
|
||||
export default NewsAnalyzer;
|
14
pages/demo.vue
Normal file
14
pages/demo.vue
Normal file
|
@ -0,0 +1,14 @@
|
|||
<script setup lang="ts">
|
||||
import CheckKidUnfriendlyContent from "~/components/checks/checkKidUnfriendlyContent";
|
||||
const title = ref("");
|
||||
const system = ref(false);
|
||||
const checkTitle = () => {
|
||||
if (!title.value) return;
|
||||
system.value = CheckKidUnfriendlyContent(title.value);
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<input type="text" v-model="title">
|
||||
<button @click="checkTitle">
|
||||
<div>{{ system }}</div>
|
||||
</template>
|
|
@ -1,6 +1,6 @@
|
|||
import sql from "~/server/components/postgres";
|
||||
export default defineEventHandler(async (event) => {
|
||||
return {
|
||||
words: ["violence"],
|
||||
words: ["violence", "kill", "太小"],
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue