Skip to content

Commit

Permalink
✔ HiH
Browse files Browse the repository at this point in the history
  • Loading branch information
bifeldy committed Oct 11, 2023
1 parent f6b7c4f commit 1bc1c54
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 24 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": 1697048301473,
"timestamp": 1697053038204,
"index": "/index.html",
"assetGroups": [
{
Expand Down
2 changes: 1 addition & 1 deletion dist/fansubid/server/main.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/api/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
cluster.on('exit', (worker, code, signal) => {
let msg = `[WORKER_${worker.id}]`;
if (signal) {
gs.log(`${msg} Killed`, signal);
gs.log(`${msg} Killed`, signal, 'error');
} else {
gs.log(`${msg} Exited`, code);
gs.log(`${msg} Exited`, code, 'error');
}
});
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/api/scheduler/rss-feed-tasks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class RssFeedTasksService {
/** */

@Cron(
CronExpression.EVERY_30_MINUTES,
CronExpression.EVERY_HOUR,
{
name: CONSTANTS.cronFansubRssFeed
}
Expand All @@ -128,8 +128,8 @@ export class RssFeedTasksService {
updated_at: 'DESC'
}
});
const rgx = new RegExp(CONSTANTS.regexUrl);
for (const fs of fansubs) {
const rgx = new RegExp(CONSTANTS.regexUrl);
if (fs.rss_feed.match(rgx)) {
try {
const feed = await this.getFeedByUrl(fs.rss_feed);
Expand Down Expand Up @@ -161,6 +161,8 @@ export class RssFeedTasksService {
const elapsedTime = endTime.getTime() - startTime.getTime();
this.gs.log('[CRON_TASK_FANSUB_RSS_FEED-END] 🐾', `${endTime} @ ${elapsedTime} ms`);
job.start();
} else {
this.sr.getCronJob(CONSTANTS.cronFansubRssFeed).stop();
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/api/scheduler/sitemap-tasks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class SitemapService {
}

@Cron(
CronExpression.EVERY_HOUR,
CronExpression.EVERY_30_MINUTES,
{
name: CONSTANTS.cronSitemap
}
Expand Down Expand Up @@ -140,6 +140,8 @@ export class SitemapService {
const elapsedTime = endTime.getTime() - startTime.getTime();
this.gs.log('[CRON_TASK_SITEMAP-END] 🐾', `${endTime} @ ${elapsedTime} ms`);
job.start();
} else {
this.sr.getCronJob(CONSTANTS.cronSitemap).stop();
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/api/scheduler/tracker-statistics-tasks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,21 @@ export class TrackerStatisticsService {
const startTime = new Date();
this.gs.log('[CRON_TASK_TRACKER_STATISTICS-START] 🐾', `${startTime}`);
try {
const url = new URL(`http://tracker.${environment.domain}/stats.json`);
const url = new URL(`http://tracker.fansub.id/stats.json`);
const res_raw = await this.api.getData(url, {
...environment.nodeJsXhrHeader
});
this.torrentTracker = await res_raw.json();
this.updateVisitor();
} catch (error) {
this.gs.log('[CRON_TASK_TRACKER_STATISTICS-ERROR] 🐾', error, 'error');
}
this.updateVisitor();
const endTime = new Date();
const elapsedTime = endTime.getTime() - startTime.getTime();
this.gs.log('[CRON_TASK_TRACKER_STATISTICS-END] 🐾', `${endTime} @ ${elapsedTime} ms`);
job.start();
} else {
this.sr.getCronJob(CONSTANTS.cronTrackerStatistics).stop();
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/api/scheduler/upload-task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class UploadService {
//
}

async uploadSubtitleAndFont(mkvAttachment: AttachmentModel) {
async uploadSubtitleAndFont(mkvAttachment: AttachmentModel): Promise<void> {
const files = readdirSync(`${environment.uploadFolder}`, { withFileTypes: true });
const fIdx = files.findIndex(f => f.name === mkvAttachment.name || f.name === `${mkvAttachment.name}.${mkvAttachment.ext}`);
if (fIdx >= 0) {
Expand Down Expand Up @@ -84,12 +84,13 @@ export class UploadService {
}
}

async extractAndUploadVideoAndZip(attachment: AttachmentModel) {
async extractAndUploadVideoAndZip(attachment: AttachmentModel): Promise<void> {
const files = readdirSync(`${environment.uploadFolder}`, { withFileTypes: true });
const fIdx = files.findIndex(f => f.name === attachment.name || f.name === `${attachment.name}.${attachment.ext}`);
if (fIdx >= 0) {
if (attachment.ext === 'mkv') {
try {
this.gs.log('[FILE_SUBTITLE_FONT-EXTRACT_MULAI] 🎼', attachment.name, 'error');
const extractedFiles = await this.mkv.mkvExtract(attachment.name, `${environment.uploadFolder}/${files[fIdx].name}`);
for (const ef of extractedFiles) {
const fileNameExt = ef.name.split('.');
Expand Down Expand Up @@ -250,6 +251,8 @@ export class UploadService {
const elapsedTime = endTime.getTime() - startTime.getTime();
this.gs.log('[CRON_TASK_UPLOAD-END] 🐾', `${endTime} @ ${elapsedTime} ms`);
job.start();
} else {
this.sr.getCronJob(CONSTANTS.cronUpload).stop();
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/api/scheduler/vps-billing-task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export class VpsBillingService {
const elapsedTime = endTime.getTime() - startTime.getTime();
this.gs.log('[CRON_TASK_VPS_BILLING-END] 🐾', `${endTime} @ ${elapsedTime} ms`);
job.start();
} else {
this.sr.getCronJob(CONSTANTS.cronVpsBilling).stop();
}
}

Expand Down
23 changes: 10 additions & 13 deletions src/api/services/mkv-extract.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export class MkvExtractService {
return new Promise((resolve, reject) => {

const startTime = Date.now();
this.gs.log(`[MKVEXTRACT_START] 📂 ${fileName} -- ${startTime} 🧬`);
this.gs.log(`[MKVEXTRACT_START] 📂 ${fileName} -- ${startTime} 🧬`, null, 'error');

const fileStream = createReadStream(filePath);
const decoder = new Decoder();
const tracks = [];
Expand All @@ -78,14 +78,15 @@ export class MkvExtractService {
let trackTypeTemp = 0;
let trackDataTemp = '';
let trackIndex = 0;

decoder.on('error', error => {
this.gs.log(`[MKVEXTRACT_ERROR] 🌋 ${fileName} 🧬`, error, 'error');
fileStream.destroy();
reject(error);
});

decoder.on('data', chunk => {
this.gs.log(`[MKVEXTRACT_CHUNK] ⌛ ${chunk[0]} -- ${chunk[1].name} -- ${chunk[1].dataSize} 🧬`);
this.gs.log(`[MKVEXTRACT_CHUNK] ⌛ ${fileName} -- ${chunk[0]} -- ${chunk[1].name} -- ${chunk[1].dataSize} 🧬`, null, 'error');
switch (chunk[0]) {
case 'end':
// if (chunk[1].name === 'Info') {
Expand Down Expand Up @@ -148,7 +149,7 @@ export class MkvExtractService {
currentFile++;
}
});

fileStream.on('end', () => {
for (const [idx, val] of trackData.entries()) {
const heading = val[0];
Expand Down Expand Up @@ -185,14 +186,10 @@ export class MkvExtractService {
});
};
const endTime = Date.now();
this.gs.log(`[MKVEXTRACT_END] 🎬 ${fileName} -- ${endTime} -- ${(endTime - startTime) / 1000} seconds 🧬`);
if (files.length === 0) {
reject(Error('No data found'));
} else {
resolve(files);
}
this.gs.log(`[MKVEXTRACT_END] 🎬 ${fileName} -- ${endTime} -- ${(endTime - startTime) / 1000} seconds 🧬`, files, 'error');
resolve(files);
});

fileStream.pipe(decoder as any);

});
Expand Down

0 comments on commit 1bc1c54

Please sign in to comment.