Skip to content

Commit

Permalink
remove: 移除不完善的分类系统
Browse files Browse the repository at this point in the history
  • Loading branch information
SALTWOOD committed Jan 19, 2025
1 parent 7086f1e commit 8535676
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 11 deletions.
3 changes: 0 additions & 3 deletions src/database/Article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import { AutoIncrement, Index, PrimaryKey, Table } from "./IDatabase.js";
title VARCHAR(24),
background TEXT,
hash CHAR(64),
category TINYINT UNSIGNED DEFAULT 0,
PRIMARY KEY (id)
`)
@Index("author", "author")
@Index("category", "category")
@AutoIncrement("id")
export class Article {
public author: number = 0;
Expand All @@ -29,7 +27,6 @@ export class Article {
public id: number = 0;
public background: string = "";
public hash: string = "";
public category: number = 0;

public getJson(contentHidden: boolean = false): any {
const toBoolean = ({ published, ...rest }: any) => ({
Expand Down
9 changes: 1 addition & 8 deletions src/routes/RouteArticles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ export class RouteArticles {

inst.app.get("/api/articles", async (req, res) => {
const user = await Utilities.getUser(req, inst.db);
const category = Number(req.query.category || "") || 0;

const articles = await inst.db.getEntities<Article>(Article);

const query = articles
.filter(a => (a.published
|| (user && (a.author === user?.id || user.permission >= 1)))
&& (category === 0 || a.category === category))
|| (user && (a.author === user?.id || user.permission >= 1))))
.map(async a => {
const author = await inst.db.getEntity<UserEntity>(UserEntity, a.author);
return {
Expand Down Expand Up @@ -68,7 +65,6 @@ export class RouteArticles {
description: string,
published: boolean,
background: string,
category: number
};

const newArticle = new Article();
Expand All @@ -79,7 +75,6 @@ export class RouteArticles {
newArticle.author = user.id;
newArticle.background = article.background ?? "";
newArticle.hash = createHash("sha256").update(newArticle.content).digest("hex");
newArticle.category = article.category ?? 0;
newArticle.lastUpdated = Date.now();

const id = await inst.db.insert(Article, newArticle);
Expand All @@ -103,7 +98,6 @@ export class RouteArticles {
description: string | undefined,
published: boolean | undefined,
background: string | undefined,
category: number | undefined,
oldHash: string
};

Expand All @@ -128,7 +122,6 @@ export class RouteArticles {
if (article.description !== undefined) newArticle.description = article.description;
if (article.published !== undefined) newArticle.published = article.published;
if (article.background !== undefined) newArticle.background = article.background;
if (article.category !== undefined) newArticle.category = article.category;
newArticle.lastUpdated = Date.now();

inst.db.update(Article, newArticle);
Expand Down

0 comments on commit 8535676

Please sign in to comment.