]> cat aescling's git repositories - mastodon.git/commitdiff
[Glitch] Gradually increase retry waiting for media processing
authorJeong Arm <kjwonmail@gmail.com>
Mon, 10 Jan 2022 13:25:08 +0000 (22:25 +0900)
committerClaire <claire.github-309c@sitedethib.com>
Sun, 16 Jan 2022 17:14:33 +0000 (18:14 +0100)
Port bc7a8ae6d6d2c2118e5c49add83539498b9d543b to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
app/javascript/flavours/glitch/actions/compose.js

index 9af8b6d2050ca16ce13d9c951b4111f2f9a61e3f..261c72b2a749608d3c9adcebf6ab7a255e5dd80f 100644 (file)
@@ -286,12 +286,15 @@ export function uploadCompose(files) {
           if (status === 200) {
             dispatch(uploadComposeSuccess(data, f));
           } else if (status === 202) {
+            let tryCount = 1;
             const poll = () => {
               api(getState).get(`/api/v1/media/${data.id}`).then(response => {
                 if (response.status === 200) {
                   dispatch(uploadComposeSuccess(response.data, f));
                 } else if (response.status === 206) {
-                  setTimeout(() => poll(), 1000);
+                  let retryAfter = (Math.log2(tryCount) || 1) * 1000;
+                  tryCount += 1;
+                  setTimeout(() => poll(), retryAfter);
                 }
               }).catch(error => dispatch(uploadComposeFail(error)));
             };