Skip to content

Commit

Permalink
✔ Delete DNS ~
Browse files Browse the repository at this point in the history
  • Loading branch information
bifeldy committed Oct 30, 2023
1 parent 0d169a6 commit b9c8f97
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 16 deletions.
74 changes: 71 additions & 3 deletions src/api/controllers/fansub-/fansub-dns.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CACHE_MANAGER, Controller, Get, HttpCode, HttpException, HttpStatus, Inject, Post, Put, Req, Res } from '@nestjs/common';
import { CACHE_MANAGER, Controller, Delete, Get, HttpCode, HttpException, HttpStatus, Inject, Post, Put, Req, Res } from '@nestjs/common';
import { ApiExcludeController } from '@nestjs/swagger';
import { Request, Response } from 'express';
import { Cache } from 'cache-manager';
Expand Down Expand Up @@ -330,7 +330,7 @@ export class FansubDnsController {
throw new HttpException({
info: `🙄 404 - Cloudflare API :: Gagal Mencari Fansub 😪`,
result: {
message: 'Data Tidak Lengkap!'
message: 'DNS Fansub Tidak Ditemukan!'
}
}, HttpStatus.NOT_FOUND);
}
Expand Down Expand Up @@ -465,7 +465,75 @@ export class FansubDnsController {
throw new HttpException({
info: `🙄 404 - Cloudflare API :: Gagal Mengubah DNS ${req.params['slug']} 😪`,
result: {
message: 'Data Tidak Lengkap!'
message: 'DNS Fansub Tidak Ditemukan!'
}
}, HttpStatus.NOT_FOUND);
}
}

// DELETE `/api/fansub-dns/:slug`
@Delete('/:slug')
@HttpCode(202)
@FilterApiKeyAccess()
@VerifiedOnly()
@Roles(RoleModel.ADMIN, RoleModel.MODERATOR, RoleModel.FANSUBBER)
async removeBySlug(@Req() req: Request, @Res({ passthrough: true }) res: Response): Promise<any> {
try {
const user: UserModel = res.locals['user'];
const group = await this.fansubMemberRepo.findOneOrFail({
where: [
{
approved: true,
fansub_: {
slug: ILike(req.params['slug'])
},
user_: {
id: Equal(user.id)
}
}
],
order: {
keterangan: 'ASC',
created_at: 'DESC'
},
relations: ['fansub_', 'user_']
});
const fansub = await this.fansubRepo.findOneOrFail({
where: [
{ slug: ILike(group.fansub_.slug) }
]
});
const result = {
dns_id: null,
dns_id_alt: null,
fansub: null
};
if (fansub.dns_id) {
result.dns_id = await this.cfs.deleteDns(fansub.dns_id);
fansub.dns_id = null;
}
if (fansub.dns_id_alt) {
result.dns_id_alt = await this.cfs.deleteDns(fansub.dns_id_alt);
fansub.dns_id_alt = null;
}
if (result.dns_id || result.dns_id_alt) {
result.fansub = await this.fansubRepo.save(fansub);
if ('user_' in result.fansub && result.fansub.user_) {
delete result.fansub.user_.created_at;
delete result.fansub.user_.updated_at;
}
return {
info: `😅 202 - Cloudflare API :: Berhasil Menghapus DNS ${req.params['slug']} 🤣`,
result
};
}
throw new Error('Data Tidak Lengkap!');
} catch (error) {
if (error instanceof HttpException) throw error;
throw new HttpException({
info: `🙄 404 - Cloudflare API :: Gagal Menghapus DNS ${req.params['slug']} 😪`,
result: {
message: 'DNS Fansub Tidak Ditemukan!'
}
}, HttpStatus.NOT_FOUND);
}
Expand Down
5 changes: 4 additions & 1 deletion src/app/_pages/user/user-list/user-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ <h2 class="border-bottom-dotted">
<div class="h-100" style="overflow-y: auto;">
<mat-selection-list [multiple]="false">
<mat-list-option class="h-100" *ngFor="let f of groupFansub" (click)="editSubDomain(f.fansub_)">
<img matListAvatar src="{{ f.fansub_.image_url }}" class="ms-3" style="border-radius: 0;" />
<img matListAvatar src="{{ f.fansub_.image_url }}" style="border-radius: 0;" />
<a mat-button matListAvatar color="accent" (click)="$event.stopPropagation(); revokeDns(f.fansub_)" style="border-radius: 0;">
<mat-icon fontIcon="delete_sweep" class="me-1"></mat-icon>
</a>
<a class="text-truncate text-decoration-none">
<span class="bg-bifeldy px-2 me-1 text-warning" style="position: absolute; right: 0;">
{{ f.updated_at | date:'d-MM-y' }}
Expand Down
62 changes: 50 additions & 12 deletions src/app/_pages/user/user-list/user-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,30 @@ export class UserListComponent implements OnInit, OnDestroy {
});
}

revokeApiKey(ak: any): void {
this.bs.busy();
this.subsRevokeApiKey = this.aks.revokeApiKey(ak.id).subscribe({
next: res => {
this.gs.log('[USER_REVOKE_APIKEY_SUCCESS]', res);
this.bs.idle();
this.getUserApiKey();
},
error: err => {
this.gs.log('[USER_REVOKE_APIKEY_ERROR]', err, 'error');
this.bs.idle();
this.getUserApiKey();
async revokeApiKey(ak: any): Promise<void> {
this.subsDialog = (await this.ds.openKonfirmasiDialog(
`Hapus API Key -- '${ak.api_key}'`,
`Apakah Yakin Akan Menghapus ${ak.ip_domain} ?`,
false
)).afterClosed().subscribe({
next: re => {
this.gs.log('[INFO_DIALOG_CLOSED]', re);
if (re === true) {
this.bs.busy();
this.subsRevokeApiKey = this.aks.revokeApiKey(ak.id).subscribe({
next: res => {
this.gs.log('[USER_REVOKE_APIKEY_SUCCESS]', res);
this.bs.idle();
this.getUserApiKey();
},
error: err => {
this.gs.log('[USER_REVOKE_APIKEY_ERROR]', err, 'error');
this.bs.idle();
this.getUserApiKey();
}
});
}
this.subsDialog.unsubscribe();
}
});
}
Expand Down Expand Up @@ -390,4 +402,30 @@ export class UserListComponent implements OnInit, OnDestroy {
this.wb.winboxOpenUri(`${environment.baseUrl}/api`, '_self', true);
}

async revokeDns(f: any): Promise<void> {
this.subsDialog = (await this.ds.openKonfirmasiDialog(
`Hapus Sub-Domain -- '${f.slug}'`,
'Apakah Yakin Ingin Menghapus / Nonaktifkan Sub-Domain ?',
false
)).afterClosed().subscribe({
next: re => {
this.gs.log('[INFO_DIALOG_CLOSED]', re);
if (re === true) {
this.bs.busy();
this.subsRevokeApiKey = this.fansub.revokeDomain(f.slug).subscribe({
next: res => {
this.gs.log('[USER_REVOKE_DNS_SUCCESS]', res);
this.bs.idle();
},
error: err => {
this.gs.log('[USER_REVOKE_DNS_ERROR]', err, 'error');
this.bs.idle();
}
});
}
this.subsDialog.unsubscribe();
}
});
}

}
4 changes: 4 additions & 0 deletions src/app/_shared/services/fansub.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,8 @@ export class FansubService {
return this.api.putData(`/fansub-dns/${fansubSlug}`, dnsData);
}

revokeDomain(fansubSlug: string): Observable<JsonResponse<any>> {
return this.api.deleteData(`/fansub-dns/${fansubSlug}`);
}

}

0 comments on commit b9c8f97

Please sign in to comment.