Skip to content

Commit 21ccbb9

Browse files
committed
feat: Add upload new version plugin via AdminCP
1 parent 1957836 commit 21ccbb9

File tree

11 files changed

+41
-69
lines changed

11 files changed

+41
-69
lines changed

packages/backend/src/core/admin/plugins/services/upload.service.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
BadRequestException,
77
ConflictException,
88
Injectable,
9-
NotImplementedException,
109
} from '@nestjs/common';
10+
import { eq } from 'drizzle-orm';
1111
import { existsSync } from 'fs';
1212
import { cp, mkdir, readFile, rm } from 'fs/promises';
1313
import { join } from 'path';
@@ -159,10 +159,6 @@ export class UploadPluginsAdminService {
159159
tempPath,
160160
});
161161

162-
if (code) {
163-
throw new NotImplementedException();
164-
}
165-
166162
// Validation
167163
if (code) {
168164
const checkPlugin =
@@ -227,7 +223,15 @@ export class UploadPluginsAdminService {
227223
tempPath,
228224
type: 'backend',
229225
}),
230-
this.databaseService.db.insert(core_plugins).values(configPlugin),
226+
code
227+
? this.databaseService.db
228+
.update(core_plugins)
229+
.set({
230+
...configPlugin,
231+
updated_at: new Date(),
232+
})
233+
.where(eq(core_plugins.code, code))
234+
: this.databaseService.db.insert(core_plugins).values(configPlugin),
231235
]);
232236
}
233237
}

packages/backend/src/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ export const nestjsMainApp = async (app: INestApplication, options?: Args) => {
4040
const config = new DocumentBuilder()
4141
.setTitle('VitNode App')
4242
.setVersion(pkg.version)
43+
.setContact('VitNode', 'https://vitnode.com/', '')
4344
.build();
4445
const document = SwaggerModule.createDocument(app, config);
4546
SwaggerModule.setup('api', app, document, {
4647
jsonDocumentUrl: '/api/swagger.json',
48+
swaggerOptions: {
49+
docExpansion: 'none',
50+
defaultModelsExpandDepth: -1,
51+
},
4752
});
4853
}
4954

packages/backend/src/utils/database/internal_database.service.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -152,28 +152,6 @@ export class InternalDatabaseService<
152152
? gt
153153
: lt;
154154
where = comparisonFn(database[primaryCursor], cursorId);
155-
156-
// ! Deleted fragment code. If you having trouble, please uncomment below code.
157-
// const cursorData = await this.db
158-
// .select()
159-
// .from(database)
160-
// .where(eq(database[primaryCursor], cursorId))
161-
// .limit(1);
162-
163-
// if (cursorData.length === 1) {
164-
// const comparisonFn = last
165-
// ? currentSortBy.direction === SortDirectionEnum.asc
166-
// ? lte
167-
// : gte
168-
// : currentSortBy.direction === SortDirectionEnum.asc
169-
// ? gt
170-
// : lt;
171-
// where = comparisonFn(
172-
// database[primaryCursor],
173-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
174-
// cursorData[0][primaryCursor as string],
175-
// );
176-
// }
177155
}
178156

179157
const [edges, [total_count]] = await Promise.all([
@@ -182,7 +160,7 @@ export class InternalDatabaseService<
182160
orderBy,
183161
limit: first || last ? ((last ? last + 1 : first) ?? 0) + 1 : undefined,
184162
}),
185-
this.db.select({ count: count() }).from(database).where(where),
163+
this.db.select({ count: count() }).from(database),
186164
]);
187165

188166
return this.outputPagination({

packages/frontend/src/api/helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ export const buildFilteredQuery = (params: Record<string, unknown>): string => {
88
!(Array.isArray(value) && value.length === 0) &&
99
value
1010
) {
11+
if (Array.isArray(value)) {
12+
value.forEach((v: string) => {
13+
searchParams.append(key, v);
14+
});
15+
16+
return;
17+
}
18+
1119
searchParams.append(
1220
key,
1321
typeof value === 'string' ? value : JSON.stringify(value),

packages/frontend/src/components/form/auto-form.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,7 @@ export function AutoForm<
134134
})}
135135

136136
{children}
137-
<div
138-
className={cn('flex w-full flex-wrap items-center gap-2', {
139-
'justify-end': !setOpen,
140-
'[&>*]:flex-1': setOpen,
141-
})}
142-
>
137+
<div className="flex w-full flex-wrap items-center justify-end gap-2">
143138
{setOpen ? (
144139
<Button
145140
disabled={form.formState.isSubmitting}

packages/frontend/src/views/admin/views/core/plugins/table/actions/delete/hooks/use-delete-plugin-admin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export const useDeletePluginAdmin = ({ id }: { id: number }) => {
1212
try {
1313
await mutationApi(id);
1414
setOpen(false);
15-
window.location.reload();
1615
} catch (_) {
1716
toast.error(tCore('title'), {
1817
description: tCore('internal_server_error'),

packages/frontend/src/views/admin/views/members/user/user-members-admin-view.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { fetcher } from '@/api/fetcher';
2-
import { Button } from '@/components/ui/button';
32
import { Card } from '@/components/ui/card';
43
import { AvatarUser } from '@/components/ui/user/avatar';
54
import { GroupFormat } from '@/components/ui/user/group-format';
6-
import { Link } from '@/navigation';
7-
import { SquareArrowOutUpRight } from 'lucide-react';
8-
import { getTranslations } from 'next-intl/server';
95
import { notFound } from 'next/navigation';
106
import { UserMembersAdmin } from 'vitnode-shared/admin/members/users.dto';
117

@@ -42,11 +38,8 @@ export const generateMetadataUserMembersAdmin = async ({ id }: Props) => {
4238
};
4339

4440
export const UserMembersAdminView = async ({ id }: Props) => {
45-
const [t, data] = await Promise.all([
46-
getTranslations('admin.members.users.item'),
47-
getData(+id),
48-
]);
49-
const { name, group, name_seo } = data;
41+
const data = await getData(+id);
42+
const { name, group } = data;
5043

5144
return (
5245
<div className="space-y-8">
@@ -66,11 +59,11 @@ export const UserMembersAdminView = async ({ id }: Props) => {
6659
<GroupFormat group={group} />
6760
</div>
6861

69-
<Button asChild variant="outline">
62+
{/* <Button asChild variant="outline">
7063
<Link href={`/profile/${name_seo}`} target="_blank">
7164
{t('public_profile')} <SquareArrowOutUpRight />
7265
</Link>
73-
</Button>
66+
</Button> */}
7467

7568
<ActionsUserMembersAdmin {...data} />
7669
</div>

packages/frontend/src/views/theme/layout/nav-bar-mobile/content/user-footer.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Separator } from '@/components/ui/separator';
22
import { useSession } from '@/hooks/use-session';
33
import { useSignOutApi } from '@/views/theme/layout/header/auth-user-bar/hooks/use-sign-out-api';
4-
import { KeyRoundIcon, LogOutIcon } from 'lucide-react';
4+
import { KeyRoundIcon, LogOutIcon, SettingsIcon } from 'lucide-react';
55
import { useTranslations } from 'next-intl';
66

77
import { ItemUserNavBarMobile } from './item';
@@ -13,6 +13,11 @@ export const UserFooterNavBarMobile = () => {
1313

1414
return (
1515
<div className="mb-4 flex flex-col px-2">
16+
<ItemUserNavBarMobile
17+
href="/settings"
18+
icon={<SettingsIcon />}
19+
name={t('settings')}
20+
/>
1621
{user?.is_admin && (
1722
<>
1823
<Separator className="my-1" />

packages/frontend/src/views/theme/layout/nav-bar-mobile/content/user-header.tsx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ import { Button } from '@/components/ui/button';
22
import { DrawerClose } from '@/components/ui/drawer';
33
import { useSession } from '@/hooks/use-session';
44
import { Link } from '@/navigation';
5-
import { SettingsIcon } from 'lucide-react';
65
import { useTranslations } from 'next-intl';
76

8-
import { ItemUserNavBarMobile } from './item';
9-
107
export const UserHeaderNavBarMobile = () => {
118
const t = useTranslations('core.global');
129
const { user } = useSession();
@@ -29,21 +26,9 @@ export const UserHeaderNavBarMobile = () => {
2926
}
3027

3128
return (
32-
<>
33-
<div className="flex flex-col gap-1 p-6 pb-4">
34-
<span className="font-semibold leading-none">{user.name}</span>
35-
<p className="text-muted-foreground text-sm leading-none">
36-
{user.email}
37-
</p>
38-
</div>
39-
40-
<div className="flex flex-col px-2">
41-
<ItemUserNavBarMobile
42-
href="/settings"
43-
icon={<SettingsIcon />}
44-
name={t('user-bar.settings')}
45-
/>
46-
</div>
47-
</>
29+
<div className="flex flex-col gap-1 p-6 pb-4">
30+
<span className="font-semibold leading-none">{user.name}</span>
31+
<p className="text-muted-foreground text-sm leading-none">{user.email}</p>
32+
</div>
4833
);
4934
};

packages/frontend/src/views/theme/layout/nav-bar-mobile/nav/nav.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const NavNavBarMobile = () => {
1010

1111
return (
1212
<Accordion asChild type="multiple">
13-
<nav className="mb-4 flex flex-col px-2">
13+
<nav className="flex flex-col px-2">
1414
{nav.map(item => (
1515
<ItemNavNavBarMobile
1616
childrenItem={item.children}

0 commit comments

Comments
 (0)