added fix to status

This commit is contained in:
PhilReact 2025-06-21 06:31:56 +03:00
parent 7e34886d15
commit fe63d9c0ff
5 changed files with 118 additions and 34 deletions

View File

@ -108,6 +108,8 @@ export const AppViewer = React.forwardRef(({ app , hide, isDevMode, skipAuth}, i
const publishLocation = e.detail?.publishLocation; const publishLocation = e.detail?.publishLocation;
const chunksSubmitted = e.detail?.chunksSubmitted; const chunksSubmitted = e.detail?.chunksSubmitted;
const totalChunks = e.detail?.totalChunks; const totalChunks = e.detail?.totalChunks;
const retry = e.detail?.retry;
const filename = e.detail?.filename;
try { try {
if (publishLocation === undefined || publishLocation === null) return; if (publishLocation === undefined || publishLocation === null) return;
const dataToBeSent = {}; const dataToBeSent = {};
@ -116,6 +118,12 @@ export const AppViewer = React.forwardRef(({ app , hide, isDevMode, skipAuth}, i
} }
if (totalChunks !== undefined && totalChunks !== null) { if (totalChunks !== undefined && totalChunks !== null) {
dataToBeSent.totalChunks = totalChunks; dataToBeSent.totalChunks = totalChunks;
}
if (retry !== undefined && retry !== null) {
dataToBeSent.retry = retry;
}
if (filename !== undefined && filename !== null) {
dataToBeSent.filename = filename;
} }
const targetOrigin = new URL(iframe.src).origin; const targetOrigin = new URL(iframe.src).origin;
iframe.contentWindow?.postMessage( iframe.contentWindow?.postMessage(

View File

@ -753,7 +753,7 @@ const sendMessage = async () => {
240000, 240000,
true true
); );
if (res !== true) if (res?.error)
throw new Error( throw new Error(
"Unable to publish image" "Unable to publish image"
); );

View File

@ -26,6 +26,10 @@ async function reusablePost(endpoint, _body) {
}, },
body: _body, body: _body,
}); });
if (!response.ok) {
const errorText = await response.text();
throw new Error(errorText);
}
let data; let data;
try { try {
data = await response.clone().json(); data = await response.clone().json();
@ -68,7 +72,46 @@ async function uploadChunkWithRetry(endpoint, formData, index, maxRetries = 3) {
throw new Error(`Chunk ${index} failed after ${maxRetries} attempts`); throw new Error(`Chunk ${index} failed after ${maxRetries} attempts`);
} }
// Wait 10 seconds before next retry // Wait 10 seconds before next retry
await new Promise((res) => setTimeout(res, 10_000)); await new Promise((res) => setTimeout(res, 25_000));
}
}
}
async function resuablePostRetry(
endpoint,
body,
maxRetries = 3,
appInfo,
resourceInfo
) {
let attempt = 0;
while (attempt < maxRetries) {
try {
const response = await reusablePost(endpoint, body);
return response;
} catch (err) {
attempt++;
if (attempt >= maxRetries) {
throw new Error(
err instanceof Error
? err?.message || `Failed to make request`
: `Failed to make request`
);
}
if (appInfo?.tabId && resourceInfo) {
executeEvent('receiveChunks', {
tabId: appInfo.tabId,
publishLocation: {
name: resourceInfo?.name,
identifier: resourceInfo?.identifier,
service: resourceInfo?.service,
},
retry: true,
});
}
// Wait 10 seconds before next retry
await new Promise((res) => setTimeout(res, 25_000));
} }
} }
} }
@ -106,7 +149,13 @@ export const publishData = async ({
}; };
const convertBytesForSigning = async (transactionBytesBase58: string) => { const convertBytesForSigning = async (transactionBytesBase58: string) => {
return await reusablePost('/transactions/convert', transactionBytesBase58); return await resuablePostRetry(
'/transactions/convert',
transactionBytesBase58,
3,
appInfo,
{ identifier, name: registeredName, service }
);
}; };
const getArbitraryFee = async () => { const getArbitraryFee = async () => {
@ -163,9 +212,12 @@ export const publishData = async ({
}; };
const processTransactionVersion2 = async (bytes) => { const processTransactionVersion2 = async (bytes) => {
return await reusablePost( return await resuablePostRetry(
'/transactions/process?apiVersion=2', '/transactions/process?apiVersion=2',
Base58.encode(bytes) Base58.encode(bytes),
3,
appInfo,
{ identifier, name: registeredName, service }
); );
}; };
@ -335,9 +387,14 @@ export const publishData = async ({
chunksSubmitted: 1, chunksSubmitted: 1,
totalChunks: 1, totalChunks: 1,
processed: false, processed: false,
filename: filename || title || `${service}-${identifier || ''}`,
}); });
} }
return await reusablePost(uploadDataUrl, postBody); return await resuablePostRetry(uploadDataUrl, postBody, 3, appInfo, {
identifier,
name: registeredName,
service,
});
} }
const file = data; const file = data;
@ -364,6 +421,8 @@ export const publishData = async ({
chunksSubmitted: 0, chunksSubmitted: 0,
totalChunks, totalChunks,
processed: false, processed: false,
filename:
file?.name || filename || title || `${service}-${identifier || ''}`,
}); });
} }
for (let index = 0; index < totalChunks; index++) { for (let index = 0; index < totalChunks; index++) {
@ -398,7 +457,7 @@ export const publishData = async ({
headers: {}, headers: {},
}); });
if (!response.ok) { if (!response?.ok) {
const errorText = await response.text(); const errorText = await response.text();
throw new Error(`Finalize failed: ${errorText}`); throw new Error(`Finalize failed: ${errorText}`);
} }

View File

@ -220,7 +220,7 @@ export const isRunningGateway = async ()=> {
case "PUBLISH_MULTIPLE_QDN_RESOURCES": { case "PUBLISH_MULTIPLE_QDN_RESOURCES": {
try { try {
const res = await publishMultipleQDNResources(request.payload, event.source, isFromExtension); const res = await publishMultipleQDNResources(request.payload, event.source, isFromExtension, appInfo);
event.source.postMessage({ event.source.postMessage({
requestId: request.requestId, requestId: request.requestId,
action: request.action, action: request.action,

View File

@ -1120,7 +1120,8 @@ export const checkArrrSyncStatus = async (seed) => {
export const publishMultipleQDNResources = async ( export const publishMultipleQDNResources = async (
data: any, data: any,
sender, sender,
isFromExtension isFromExtension,
appInfo
) => { ) => {
const requiredFields = ['resources']; const requiredFields = ['resources'];
const missingFields: string[] = []; const missingFields: string[] = [];
@ -1168,6 +1169,23 @@ export const publishMultipleQDNResources = async (
); );
} }
const totalFileSize = resources.reduce((acc, resource) => {
const file = resource?.file;
if (file && file?.size && !isNaN(file?.size)) {
return acc + file.size;
}
return acc;
}, 0);
if (totalFileSize > 0) {
const urlCheck = `/arbitrary/check/tmp?totalSize=${totalFileSize}`;
const checkEndpoint = await createEndpoint(urlCheck);
const checkRes = await fetch(checkEndpoint);
if (!checkRes.ok) {
throw new Error('Not enough space on your hard drive');
}
}
const encrypt = data?.encrypt; const encrypt = data?.encrypt;
for (const resource of resources) { for (const resource of resources) {
@ -1289,6 +1307,7 @@ export const publishMultipleQDNResources = async (
throw new Error('User declined request'); throw new Error('User declined request');
} }
let failedPublishesIdentifiers = []; let failedPublishesIdentifiers = [];
const publishedResponses = [];
for (const resource of resources) { for (const resource of resources) {
try { try {
const requiredFields = ['service']; const requiredFields = ['service'];
@ -1389,30 +1408,28 @@ export const publishMultipleQDNResources = async (
resource?.base64 || resource?.data64 || resourceEncrypt resource?.base64 || resource?.data64 || resourceEncrypt
? 'base64' ? 'base64'
: 'file'; : 'file';
await retryTransaction( const response = await publishData({
publishData, apiVersion: 2,
[ category,
{
data: rawData, data: rawData,
description,
filename: filename,
identifier: encodeURIComponent(identifier),
registeredName: encodeURIComponent(resource?.name || name), registeredName: encodeURIComponent(resource?.name || name),
service: service, service: service,
identifier: encodeURIComponent(identifier),
uploadType: dataType,
filename: filename,
title,
description,
category,
tag1, tag1,
tag2, tag2,
tag3, tag3,
tag4, tag4,
tag5, tag5,
apiVersion: 2, title,
uploadType: dataType,
withFee: true, withFee: true,
}, appInfo,
], });
true if (response?.signature) {
); publishedResponses.push(response);
}
await new Promise((res) => { await new Promise((res) => {
setTimeout(() => { setTimeout(() => {
res(); res();
@ -1454,7 +1471,7 @@ export const publishMultipleQDNResources = async (
true true
); );
} }
return true; return publishedResponses;
}; };
export const voteOnPoll = async (data, isFromExtension) => { export const voteOnPoll = async (data, isFromExtension) => {