Skip to content

Commit

Permalink
✔ Ipo-chan Proxy URL ~
Browse files Browse the repository at this point in the history
  • Loading branch information
bifeldy committed Sep 7, 2024
1 parent 1d7e696 commit 5e5c7a5
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/main-site/server/main.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import { ILike } from 'typeorm';

import { CONSTANTS } from '../../../constants';

import { environment } from '../../../environments/api/environment';

import { GlobalService } from '../../services/global.service';

import { FansubService } from '../../repository/fansub.service';
import { RssFeedService } from '../../repository/rss-feed.service';

@Controller('/fansub-rss-feed')
export class FansubRssFeedController {

constructor(
private gs: GlobalService,
private fansubRepo: FansubService,
private rssFeedRepo: RssFeedService
) {
Expand Down Expand Up @@ -80,7 +85,11 @@ export class FansubRssFeedController {
f.urls = rf.f_urls;
f.rss_feed = rf.f_rss_feed;
f.tags = rf.f_tags;
f.image_url = rf.f_image_url;
let imgUrl = rf.f_image_url;
if (imgUrl?.startsWith('http') && this.gs.includesOneOf(imgUrl, environment.ipoChanProxyUrl)) {
imgUrl = `https://crawl.${environment.domain}/?url=${encodeURIComponent(imgUrl)}`;
}
f.image_url = imgUrl;
f.view_count = rf.f_view_count;
f.like_count = rf.f_like_count;
f.dns_id = rf.f_dns_id;
Expand Down
10 changes: 10 additions & 0 deletions projects/main-site/src/api/controllers/project-type.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { Equal } from 'typeorm';

import { RoleModel } from '../../models/req-res.model';

import { environment } from '../../environments/api/environment';

import { FilterApiKeyAccess } from '../decorators/filter-api-key-access.decorator';
import { Roles } from '../decorators/roles.decorator';
import { VerifiedOnly } from '../decorators/verified-only.decorator';

import { GlobalService } from '../services/global.service';

import { BerkasService } from '../repository/berkas.service';
import { ProjectTypeService } from '../repository/project-type.service';

Expand All @@ -17,6 +21,7 @@ import { ProjectTypeService } from '../repository/project-type.service';
export class ProjectTypeController {

constructor(
private gs: GlobalService,
private berkasRepo: BerkasService,
private projectTypeRepo: ProjectTypeService
) {
Expand Down Expand Up @@ -65,6 +70,11 @@ export class ProjectTypeController {
ORDER BY
x.name ASC
`);
for (const p of projects) {
if (p.image_url?.startsWith('http') && this.gs.includesOneOf(p.image_url, environment.ipoChanProxyUrl)) {
p.image_url = `https://crawl.${environment.domain}/?url=${encodeURIComponent(p.image_url)}`;
}
}
return {
info: `😅 200 - Project API :: List All 🤣`,
count: projects.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import { Request, Response } from 'express';

import { CONSTANTS } from '../../../constants';

import { environment } from '../../../environments/api/environment';

import { GlobalService } from '../../services/global.service';

import { UserService } from '../../repository/user.service';

@Controller('/quiz-leaderboard')
export class QuizLeaderboardController {

constructor(
private gs: GlobalService,
private userRepo: UserService
) {
//
Expand All @@ -32,7 +37,7 @@ export class QuizLeaderboardController {
FROM
(
SELECT
count(*)
count(*) count
FROM
users u,
profile p
Expand Down Expand Up @@ -69,6 +74,11 @@ export class QuizLeaderboardController {
}
delete l.count;
}
if ('image_url' in l) {
if (l.image_url?.startsWith('http') && this.gs.includesOneOf(l.image_url, environment.ipoChanProxyUrl)) {
l.image_url = `https://crawl.${environment.domain}/?url=${encodeURIComponent(l.image_url)}`;
}
}
}
return {
info: `😅 200 - Leaderboard API :: List Rank 🤣`,
Expand Down
9 changes: 9 additions & 0 deletions projects/main-site/src/api/services/global.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,13 @@ export class GlobalService {
return false;
}

includesOneOf(text: string, arr: string[]): boolean {
for (const a of arr) {
if (text?.includes(a)) {
return true;
}
}
return false;
}

}
43 changes: 39 additions & 4 deletions projects/main-site/src/api/services/quiz.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { EntityManager } from 'typeorm';

import { CONSTANTS } from '../../constants';

import { environment } from '../../environments/api/environment';

import { QuizCategoryModel, QuizHirakataModel, QuizKanjiModel, QuizModel } from '../../models/quiz.model';
import { RoomInfoInOutModel } from '../../models/socket-io.model';

Expand Down Expand Up @@ -85,7 +87,13 @@ export class QuizService {
DROP TABLE IF EXISTS hirakata_quiz;
CREATE TABLE hirakata_quiz AS
SELECT
*
romaji,
hiragana,
katakana,
category,
segment,
created_at,
updated_at
FROM
hirakata
WHERE
Expand All @@ -107,7 +115,13 @@ export class QuizService {
`);
hirakatas = await this.manager.query(`
SELECT
*
romaji,
hiragana,
katakana,
category,
segment,
created_at,
updated_at
FROM
hirakata_quiz
`);
Expand Down Expand Up @@ -155,7 +169,16 @@ export class QuizService {
DROP TABLE IF EXISTS nihongo_${category}_quiz;
CREATE TABLE nihongo_${category}_quiz AS
SELECT
*
id,
romaji,
kana,
meaning,
category,
audio,
image_url,
user_id,
created_at,
updated_at
FROM
nihongo
WHERE
Expand All @@ -174,14 +197,26 @@ export class QuizService {
`);
nihongo = await this.manager.query(`
SELECT
*
id,
romaji,
kana,
meaning,
category,
audio,
image_url,
user_id,
created_at,
updated_at
FROM
nihongo_${category}_quiz
`);
for (const h of nihongo) {
delete h.created_at;
delete h.updated_at;
delete h.user_id;
if (h.image_url?.startsWith('http') && this.gs.includesOneOf(h.image_url, environment.ipoChanProxyUrl)) {
h.image_url = `https://crawl.${environment.domain}/?url=${encodeURIComponent(h.image_url)}`;
}
}
const randomInteger = this.getRandomInt(0, nihongo.length - 1);
return {
Expand Down
11 changes: 10 additions & 1 deletion projects/main-site/src/api/transformers/ipo-chan.transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import { environment } from '../../environments/api/environment';

export class IpoChanTransformer implements ValueTransformer {

private includesOneOf(text: string, arr: string[]): boolean {
for (const a of arr) {
if (text?.includes(a)) {
return true;
}
}
return false;
}

// Used to marshal data when writing to the database.
to(data: string): string {
return data
Expand All @@ -12,7 +21,7 @@ export class IpoChanTransformer implements ValueTransformer {
// Used to unmarshal data when reading from the database.
from(data: string): string {
let imgUrl = data;
if (imgUrl?.startsWith('http') && !imgUrl?.includes(environment.s3Compatible.bucket)) {
if (imgUrl?.startsWith('http') && this.includesOneOf(imgUrl, environment.ipoChanProxyUrl)) {
imgUrl = `https://crawl.${environment.domain}/?url=${encodeURIComponent(imgUrl)}`;
}
return imgUrl;
Expand Down
5 changes: 4 additions & 1 deletion projects/main-site/src/environments/api/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,8 @@ export const environment = {
region: 'auto',
accessKeyId: SECRETS().S3_ACCESS_KEY_ID, // '',
secretAccessKey: SECRETS().S3_SECRET_ACCESS_KEY // '',
}
},
ipoChanProxyUrl: [
'i.ibb.co'
]
};

0 comments on commit 5e5c7a5

Please sign in to comment.