Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #262 #266

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"arctic": "^1.9.0",
"drizzle-orm": "^0.30.10",
"elysia": "^1.0.21",
"elysia-oauth2": "^1.2.0",
"elysia-oauth2": "1.2.0",
"feed": "^4.2.2",
"jose": "^5.3.0",
"reflect-metadata": "^0.2.2",
Expand Down
26 changes: 18 additions & 8 deletions server/src/services/tag.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { eq } from "drizzle-orm";
import { and, eq } from "drizzle-orm";
import Elysia from "elysia";
import type { DB } from "../_worker";
import { feedHashtags, hashtags } from "../db/schema";
import { getDB } from "../utils/di";
import { setup } from "../setup";

export function TagService() {
const db: DB = getDB();
return new Elysia({ aot: false })
.use(setup())
.group('/tag', (group) =>
group
.get('/', async () => {
Expand All @@ -24,15 +26,19 @@ export function TagService() {
}
})
})
.get('/:name', async ({ set, params: { name } }) => {
.get('/:name', async ({ admin, set, params: { name } }) => {
const nameDecoded = decodeURI(name)
const tag = await db.query.hashtags.findFirst({
where: eq(hashtags.name, nameDecoded),
with: {
feeds: {
with: {
feed: {
columns: { id: true, title: true, summary: true, content: true, createdAt: true, updatedAt: true },
columns: {
id: true, title: true, summary: true, content: true, createdAt: true, updatedAt: true,
draft: false,
listed: false
},
with: {
user: {
columns: { id: true, username: true, avatar: true }
Expand All @@ -45,18 +51,22 @@ export function TagService() {
}
}
}
}
}
},
where: (feeds: any) => admin ? undefined : and(eq(feeds.draft, 0), eq(feeds.listed, 1)),
} as any
}
}
}
});
const tagFeeds = tag?.feeds.map((tag) => {
const tagFeeds = tag?.feeds.map((tag: any) => {
if (!tag.feed) {
return null;
}
return {
...tag.feed,
hashtags: tag.feed.hashtags.map((tag) => tag.hashtag)
hashtags: tag.feed.hashtags.map((tag: any) => tag.hashtag)
}
})
}).filter((feed: any) => feed !== null);
if (!tag) {
set.status = 404;
return 'Not found';
Expand Down