Skip to content

Commit

Permalink
✔ Fansub :: Anime & Dorama
Browse files Browse the repository at this point in the history
  • Loading branch information
bifeldy committed Jun 11, 2023
1 parent fd3fccd commit a5de042
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 20 deletions.
2 changes: 1 addition & 1 deletion dist/fansubid/browser/ngsw.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"configVersion": 1,
"timestamp": 1686474931321,
"timestamp": 1686497044734,
"index": "/index.html",
"assetGroups": [
{
Expand Down
2 changes: 1 addition & 1 deletion dist/fansubid/server/main.js

Large diffs are not rendered by default.

44 changes: 35 additions & 9 deletions src/api/controllers/fansub-/fansub-anime.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import { Request, Response } from 'express';

import { FilterApiKeyAccess } from '../../decorators/filter-api-key-access.decorator';

import { AnimeService } from '../../repository/anime.service';
import { BerkasService } from '../../repository/berkas.service';
import { FansubService } from '../../repository/fansub.service';

@ApiExcludeController()
@Controller('/fansub-anime')
export class FansubAnimeController {

constructor(
private berkasRepo: BerkasService
private animeRepo: AnimeService,
private berkasRepo: BerkasService,
private fansubRepo: FansubService
) {
//
}
Expand All @@ -32,13 +36,29 @@ export class FansubAnimeController {
.leftJoinAndSelect('berkas.fansub_', 'fansub_')
.where('fansub_.id IN (:...id)', { id: fansubId })
.andWhere('berkas.anime_ IS NOT NULL')
.orderBy('anime_.name', 'ASC');
if (fansubId.length === 1) {
fileRepoQuery = fileRepoQuery
.skip(queryPage > 0 ? (queryPage * queryRow - queryRow) : 0)
.take((queryRow > 0 && queryRow <= 500) ? queryRow : 10);
.orderBy('anime_.name', 'ASC')
.orderBy('fansub_.id', 'ASC')
.select(['anime_', 'fansub_'])
.groupBy('anime_.id')
.addGroupBy('fansub_.id');
const filesRaw = await fileRepoQuery.getRawMany();
const files = [];
for (const fr of filesRaw) {
const berkas = this.berkasRepo.new();
berkas.anime_ = this.animeRepo.new();
berkas.fansub_ = [];
for (const [key, value] of Object.entries(fr)) {
const k = key.split('__');
if (Array.isArray(berkas[`${k[0]}_`])) {
const fansub_ = this.fansubRepo.new();
fansub_[k[1]] = value;
berkas[`${k[0]}_`].push(fansub_);
} else {
berkas[`${k[0]}_`][k[1]] = value;
}
}
files.push(berkas);
}
const [files, count] = await fileRepoQuery.getManyAndCount();
const results: any = {};
for (const i of fansubId) {
results[i] = [];
Expand All @@ -61,8 +81,14 @@ export class FansubAnimeController {
.filter((a, b, c) => c.findIndex(d => (d.id === a.id)) === b)
.sort((a, b) => (a.name > b.name) ? 1 : -1);
}
if (fansubId.length > 1) {
for (const i of fansubId) {
let count = 0;
for (const i of fansubId) {
count += results[i].length;
if (fansubId.length === 1) {
const start = (queryPage ? (queryPage - 1) * (queryRow ? queryRow : 10) : 0);
const end = (queryPage ? (queryPage - 1) * (queryRow ? queryRow : 10) : 0) + (queryRow ? queryRow : 10);
results[i] = results[i].slice(start, end);
} else {
results[i] = results[i].length;
}
}
Expand Down
44 changes: 35 additions & 9 deletions src/api/controllers/fansub-/fansub-dorama.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import { Request, Response } from 'express';
import { FilterApiKeyAccess } from '../../decorators/filter-api-key-access.decorator';

import { BerkasService } from '../../repository/berkas.service';
import { DoramaService } from '../../repository/dorama.service';
import { FansubService } from '../../repository/fansub.service';

@ApiExcludeController()
@Controller('/fansub-dorama')
export class FansubDoramaController {

constructor(
private berkasRepo: BerkasService
private doramaRepo: DoramaService,
private berkasRepo: BerkasService,
private fansubRepo: FansubService
) {
//
}
Expand All @@ -32,13 +36,29 @@ export class FansubDoramaController {
.leftJoinAndSelect('berkas.fansub_', 'fansub_')
.where('fansub_.id IN (:...id)', { id: fansubId })
.andWhere('berkas.dorama_ IS NOT NULL')
.orderBy('dorama_.name', 'ASC');
if (fansubId.length === 1) {
fileRepoQuery = fileRepoQuery
.skip(queryPage > 0 ? (queryPage * queryRow - queryRow) : 0)
.take((queryRow > 0 && queryRow <= 500) ? queryRow : 10);
.orderBy('dorama_.name', 'ASC')
.orderBy('fansub_.id', 'ASC')
.select(['dorama_', 'fansub_'])
.groupBy('dorama_.id')
.addGroupBy('fansub_.id');
const filesRaw = await fileRepoQuery.getRawMany();
const files = [];
for (const fr of filesRaw) {
const berkas = this.berkasRepo.new();
berkas.dorama_ = this.doramaRepo.new();
berkas.fansub_ = [];
for (const [key, value] of Object.entries(fr)) {
const k = key.split('__');
if (Array.isArray(berkas[`${k[0]}_`])) {
const fansub_ = this.fansubRepo.new();
fansub_[k[1]] = value;
berkas[`${k[0]}_`].push(fansub_);
} else {
berkas[`${k[0]}_`][k[1]] = value;
}
}
files.push(berkas);
}
const [files, count] = await fileRepoQuery.getManyAndCount();
const results: any = {};
for (const i of fansubId) {
results[i] = [];
Expand All @@ -61,8 +81,14 @@ export class FansubDoramaController {
.filter((a, b, c) => c.findIndex(d => (d.id === a.id)) === b)
.sort((a, b) => (a.name > b.name) ? 1 : -1);
}
if (fansubId.length > 1) {
for (const i of fansubId) {
let count = 0;
for (const i of fansubId) {
count += results[i].length;
if (fansubId.length === 1) {
const start = (queryPage ? (queryPage - 1) * (queryRow ? queryRow : 10) : 0);
const end = (queryPage ? (queryPage - 1) * (queryRow ? queryRow : 10) : 0) + (queryRow ? queryRow : 10);
results[i] = results[i].slice(start, end);
} else {
results[i] = results[i].length;
}
}
Expand Down

0 comments on commit a5de042

Please sign in to comment.