Skip to content

Commit

Permalink
feat: Add upload new version plugin via AdminCP
Browse files Browse the repository at this point in the history
  • Loading branch information
aXenDeveloper committed Dec 21, 2024
1 parent 1957836 commit 21ccbb9
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 69 deletions.
16 changes: 10 additions & 6 deletions packages/backend/src/core/admin/plugins/services/upload.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
BadRequestException,
ConflictException,
Injectable,
NotImplementedException,
} from '@nestjs/common';
import { eq } from 'drizzle-orm';
import { existsSync } from 'fs';
import { cp, mkdir, readFile, rm } from 'fs/promises';
import { join } from 'path';
Expand Down Expand Up @@ -159,10 +159,6 @@ export class UploadPluginsAdminService {
tempPath,
});

if (code) {
throw new NotImplementedException();
}

// Validation
if (code) {
const checkPlugin =
Expand Down Expand Up @@ -227,7 +223,15 @@ export class UploadPluginsAdminService {
tempPath,
type: 'backend',
}),
this.databaseService.db.insert(core_plugins).values(configPlugin),
code
? this.databaseService.db
.update(core_plugins)
.set({
...configPlugin,
updated_at: new Date(),
})
.where(eq(core_plugins.code, code))
: this.databaseService.db.insert(core_plugins).values(configPlugin),
]);
}
}
5 changes: 5 additions & 0 deletions packages/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ export const nestjsMainApp = async (app: INestApplication, options?: Args) => {
const config = new DocumentBuilder()
.setTitle('VitNode App')
.setVersion(pkg.version)
.setContact('VitNode', 'https://vitnode.com/', '')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document, {
jsonDocumentUrl: '/api/swagger.json',
swaggerOptions: {
docExpansion: 'none',
defaultModelsExpandDepth: -1,
},
});
}

Expand Down
24 changes: 1 addition & 23 deletions packages/backend/src/utils/database/internal_database.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,28 +152,6 @@ export class InternalDatabaseService<
? gt
: lt;
where = comparisonFn(database[primaryCursor], cursorId);

// ! Deleted fragment code. If you having trouble, please uncomment below code.
// const cursorData = await this.db
// .select()
// .from(database)
// .where(eq(database[primaryCursor], cursorId))
// .limit(1);

// if (cursorData.length === 1) {
// const comparisonFn = last
// ? currentSortBy.direction === SortDirectionEnum.asc
// ? lte
// : gte
// : currentSortBy.direction === SortDirectionEnum.asc
// ? gt
// : lt;
// where = comparisonFn(
// database[primaryCursor],
// // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
// cursorData[0][primaryCursor as string],
// );
// }
}

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

return this.outputPagination({
Expand Down
8 changes: 8 additions & 0 deletions packages/frontend/src/api/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ export const buildFilteredQuery = (params: Record<string, unknown>): string => {
!(Array.isArray(value) && value.length === 0) &&
value
) {
if (Array.isArray(value)) {
value.forEach((v: string) => {
searchParams.append(key, v);
});

return;
}

searchParams.append(
key,
typeof value === 'string' ? value : JSON.stringify(value),
Expand Down
7 changes: 1 addition & 6 deletions packages/frontend/src/components/form/auto-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,7 @@ export function AutoForm<
})}

{children}
<div
className={cn('flex w-full flex-wrap items-center gap-2', {
'justify-end': !setOpen,
'[&>*]:flex-1': setOpen,
})}
>
<div className="flex w-full flex-wrap items-center justify-end gap-2">
{setOpen ? (
<Button
disabled={form.formState.isSubmitting}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const useDeletePluginAdmin = ({ id }: { id: number }) => {
try {
await mutationApi(id);
setOpen(false);
window.location.reload();
} catch (_) {
toast.error(tCore('title'), {
description: tCore('internal_server_error'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { fetcher } from '@/api/fetcher';
import { Button } from '@/components/ui/button';
import { Card } from '@/components/ui/card';
import { AvatarUser } from '@/components/ui/user/avatar';
import { GroupFormat } from '@/components/ui/user/group-format';
import { Link } from '@/navigation';
import { SquareArrowOutUpRight } from 'lucide-react';
import { getTranslations } from 'next-intl/server';
import { notFound } from 'next/navigation';
import { UserMembersAdmin } from 'vitnode-shared/admin/members/users.dto';

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

export const UserMembersAdminView = async ({ id }: Props) => {
const [t, data] = await Promise.all([
getTranslations('admin.members.users.item'),
getData(+id),
]);
const { name, group, name_seo } = data;
const data = await getData(+id);
const { name, group } = data;

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

<Button asChild variant="outline">
{/* <Button asChild variant="outline">
<Link href={`/profile/${name_seo}`} target="_blank">
{t('public_profile')} <SquareArrowOutUpRight />
</Link>
</Button>
</Button> */}

<ActionsUserMembersAdmin {...data} />
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Separator } from '@/components/ui/separator';
import { useSession } from '@/hooks/use-session';
import { useSignOutApi } from '@/views/theme/layout/header/auth-user-bar/hooks/use-sign-out-api';
import { KeyRoundIcon, LogOutIcon } from 'lucide-react';
import { KeyRoundIcon, LogOutIcon, SettingsIcon } from 'lucide-react';
import { useTranslations } from 'next-intl';

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

return (
<div className="mb-4 flex flex-col px-2">
<ItemUserNavBarMobile
href="/settings"
icon={<SettingsIcon />}
name={t('settings')}
/>
{user?.is_admin && (
<>
<Separator className="my-1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import { Button } from '@/components/ui/button';
import { DrawerClose } from '@/components/ui/drawer';
import { useSession } from '@/hooks/use-session';
import { Link } from '@/navigation';
import { SettingsIcon } from 'lucide-react';
import { useTranslations } from 'next-intl';

import { ItemUserNavBarMobile } from './item';

export const UserHeaderNavBarMobile = () => {
const t = useTranslations('core.global');
const { user } = useSession();
Expand All @@ -29,21 +26,9 @@ export const UserHeaderNavBarMobile = () => {
}

return (
<>
<div className="flex flex-col gap-1 p-6 pb-4">
<span className="font-semibold leading-none">{user.name}</span>
<p className="text-muted-foreground text-sm leading-none">
{user.email}
</p>
</div>

<div className="flex flex-col px-2">
<ItemUserNavBarMobile
href="/settings"
icon={<SettingsIcon />}
name={t('user-bar.settings')}
/>
</div>
</>
<div className="flex flex-col gap-1 p-6 pb-4">
<span className="font-semibold leading-none">{user.name}</span>
<p className="text-muted-foreground text-sm leading-none">{user.email}</p>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const NavNavBarMobile = () => {

return (
<Accordion asChild type="multiple">
<nav className="mb-4 flex flex-col px-2">
<nav className="flex flex-col px-2">
{nav.map(item => (
<ItemNavNavBarMobile
childrenItem={item.children}
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/admin/members/users.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class UsersMembersAdminQuery extends PaginationQuery {
@IsArray()
@IsOptional()
@IsString({ each: true })
@Transform(({ value }) => value.split(','))
@Transform(({ value }) => (Array.isArray(value) ? value : [value]))
groups?: number[];

@ApiPropertyOptional()
Expand Down

0 comments on commit 21ccbb9

Please sign in to comment.