Skip to content

Commit

Permalink
✔ Upload Re-Try Max Count
Browse files Browse the repository at this point in the history
  • Loading branch information
bifeldy committed Jun 8, 2023
1 parent a32a342 commit 5ffde08
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 30 deletions.
2 changes: 1 addition & 1 deletion dist/fansubid/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<noscript>🎉 Harap Menyalakan JavaScript Untuk Dapat Mengakses Website Ini ✨</noscript>
</div>
<app-root></app-root>
<script src="runtime.5d0a5fd81191b459.js" type="module"></script><script src="polyfills.325a71d3e423341a.js" type="module"></script><script src="scripts.03e7a8120a25f41a.js" defer></script><script src="main.02d56f70e2c0cfce.js" type="module"></script>
<script src="runtime.5d0a5fd81191b459.js" type="module"></script><script src="polyfills.325a71d3e423341a.js" type="module"></script><script src="scripts.03e7a8120a25f41a.js" defer></script><script src="main.2e80a5914d6d73f2.js" type="module"></script>


</body></html>
1 change: 0 additions & 1 deletion dist/fansubid/browser/main.02d56f70e2c0cfce.js

This file was deleted.

1 change: 1 addition & 0 deletions dist/fansubid/browser/main.2e80a5914d6d73f2.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/fansubid/browser/ngsw.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"configVersion": 1,
"timestamp": 1685966166045,
"timestamp": 1686236999606,
"index": "/index.html",
"assetGroups": [
{
Expand Down Expand Up @@ -41,7 +41,7 @@
"/common.5fac99215f993fa1.js",
"/favicon.ico",
"/index.html",
"/main.02d56f70e2c0cfce.js",
"/main.2e80a5914d6d73f2.js",
"/manifest.webmanifest",
"/polyfills.325a71d3e423341a.js",
"/runtime.5d0a5fd81191b459.js",
Expand Down Expand Up @@ -114,8 +114,8 @@
"/960.cf76071ca1fb40b4.js": "7b413c0e87b4c1be4b7d993ac0e7404202d47786",
"/common.5fac99215f993fa1.js": "fcdb5841f1085e2aa8ead5ee32402b3ea2ead2cb",
"/favicon.ico": "071facb8fab2e4b3493dcfbb0b02d7bd21bca97e",
"/index.html": "d533d1d47fd59c8459fc8f56bff45fb0a9757f50",
"/main.02d56f70e2c0cfce.js": "25753a9027cc012d6c37b2205cfedb27c4951b90",
"/index.html": "dc20aa78325f115be5289f522081d497abc9987b",
"/main.2e80a5914d6d73f2.js": "a352f692b79597b32b5982eafa0e9af4c61fa02e",
"/manifest.webmanifest": "eafb5426cdc9fd714787e5453af315b9972875a3",
"/polyfills.325a71d3e423341a.js": "18f8a8b77e7d11be1385d438c6d218cc68c0edb3",
"/runtime.5d0a5fd81191b459.js": "779b94c7339a7c3e10b0f2c124d3b9cb751f0276",
Expand Down
2 changes: 1 addition & 1 deletion dist/fansubid/server/main.js

Large diffs are not rendered by default.

57 changes: 34 additions & 23 deletions src/api/services/discord.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,33 +128,44 @@ export class DiscordService {
highWaterMark: CONSTANTS.fileSizeAttachmentChunkDiscordLimit
}
);
const ddlChunks = [];
for await (const c of crs) {
this.gs.log('[DISCORD_SERVICE-CHUNK] 🎉', c.length);
if (!chunkIdx || chunkIdx === currentChunkIdx) {
try {
const botDdlChannel = this.bot ? (this.bot.channels.cache.get(environment.discord.channelDdlId) as NewsChannel) : null;
if (botDdlChannel) {
const msg = await botDdlChannel.send({
files: [new MessageAttachment(c, `${attachment.name}_${currentChunkIdx}`)]
});
if (currentChunkIdx === 0) {
chunkParent = msg.id;
} else if (attachment.discord) {
chunkParent = attachment.discord;
let uploadTryCount = 1;
while (uploadTryCount > 0) {
if (uploadTryCount > CONSTANTS.retryDdlUploadMaxCount) {
await this.ddlFileRepo.remove(ddlChunks);
throw 'Gagal Upload Ke Discord';
}
try {
this.gs.log(`[DISCORD_SERVICE-CHUNK_${currentChunkIdx}_TRY_${uploadTryCount}] 🎉`, c.length);
const botDdlChannel = this.bot ? (this.bot.channels.cache.get(environment.discord.channelDdlId) as NewsChannel) : null;
if (botDdlChannel) {
const msg = await botDdlChannel.send({
files: [new MessageAttachment(c, `${attachment.name}_${currentChunkIdx}`)]
});
if (currentChunkIdx === 0) {
chunkParent = msg.id;
} else if (attachment.discord) {
chunkParent = attachment.discord;
}
const ddlFile = this.ddlFileRepo.new();
ddlFile.msg_id = chunkParent;
ddlFile.chunk_idx = currentChunkIdx;
ddlFile.user_ = user;
ddlFile.id = msg.attachments.first().id;
ddlFile.name = msg.attachments.first().name;
ddlFile.url = msg.attachments.first().url;
ddlFile.size = msg.attachments.first().size;
ddlFile.mime = attachment.mime;
const resSaveDdlFile = await this.ddlFileRepo.save(ddlFile);
ddlChunks.push(resSaveDdlFile);
}
const ddlFile = this.ddlFileRepo.new();
ddlFile.msg_id = chunkParent;
ddlFile.chunk_idx = currentChunkIdx;
ddlFile.user_ = user;
ddlFile.id = msg.attachments.first().id;
ddlFile.name = msg.attachments.first().name;
ddlFile.url = msg.attachments.first().url;
ddlFile.size = msg.attachments.first().size;
ddlFile.mime = attachment.mime;
await this.ddlFileRepo.save(ddlFile);
break;
} catch (error) {
this.gs.log(`[DISCORD_SERVICE-SEND_ATTACHMMENT_ERROR_${currentChunkIdx}_TRY_${uploadTryCount}] 🎉`, error, 'error');
uploadTryCount++;
}
} catch (error) {
this.gs.log('[DISCORD_SERVICE-SEND_ATTACHMMENT_ERROR] 🎉', error, 'error');
}
}
currentChunkIdx++;
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const CONSTANTS = {
regexEnglishKeyboardKeys: /^[a-zA-Z0-9~`!@#\$%\^&\*\(\)_\-\+={\[\}\]\|\\:;"'<,>\.\?\/ \n]*$/,
regexJapaneseKeyboardKeys: /[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9々〆〤、。]+/u,
regexUrl: /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/,
retryDdlUploadMaxCount: 5,
socketRoomNameGlobalPublic: 'GLOBAL_PUBLIK',
socketRoomNameGlobalFansub: 'GLOBAL_FANSUB',
socketRoomNameServerLogs: 'SERVER_LOGS',
Expand Down

0 comments on commit 5ffde08

Please sign in to comment.