diff --git a/package.json b/package.json index f859328504c..50d87ba876c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "yarn": ">=999.0.0", "npm": ">=999.0.0" }, - "version": "2.34.0", + "version": "2.34.1", "private": true, "license": "AGPL-3.0-or-later", "scripts": { diff --git a/packages/mask/.webpack/config.ts b/packages/mask/.webpack/config.ts index 6ac55ff5bed..d96133d4179 100644 --- a/packages/mask/.webpack/config.ts +++ b/packages/mask/.webpack/config.ts @@ -50,7 +50,9 @@ export async function createConfiguration( console.error("Environment variable WEB3_CONSTANTS_RPC should be JSON.stringify'ed twice") WEB3_CONSTANTS_RPC = JSON.stringify(WEB3_CONSTANTS_RPC) } - } catch (err) {} + } catch (err) { + console.error('Environment variable WEB3_CONSTANTS_RPC is not valid JSON') + } } const baseConfig = { name: 'mask', @@ -68,7 +70,7 @@ export async function createConfiguration( experiments: rspack ? { futureDefaults: true } - : { + : { futureDefaults: true, deferImport: true, }, @@ -98,8 +100,8 @@ export async function createConfiguration( alias[require.resolve('@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js')] = // alias[ - join(require.resolve('@rspack/plugin-react-refresh/package.json'), '../') + - 'client/reactRefreshEntry.js' + join(require.resolve('@rspack/plugin-react-refresh/package.json'), '../') + + 'client/reactRefreshEntry.js' ] = require.resolve('./package-overrides/null.mjs') } return alias @@ -126,7 +128,7 @@ export async function createConfiguration( // Source map for libraries !rspack && computedFlags.sourceMapKind ? { test: /\.js$/, enforce: 'pre', use: [require.resolve('source-map-loader')] } - : null, + : null, // TypeScript { test: /\.[mc]?[jt]sx?$/i, @@ -170,7 +172,7 @@ export async function createConfiguration( sources: (x) => x.endsWith('.tsx') || !!x.match(/use[A-Z]/), }), } - : undefined!, + : undefined!, ].filter(Boolean), }, // compress svg files @@ -188,7 +190,7 @@ export async function createConfiguration( dependency: 'url', type: 'asset/resource', } - : null, + : null, ], }, plugins: [ @@ -202,7 +204,7 @@ export async function createConfiguration( runChecks: true, diagnosticsVerbosity: 1, }) - : undefined, + : undefined, new WebExtensionPlugin({ background: { pageEntry: 'background', serviceWorkerEntry: 'backgroundWorker' }, experimental_output: { @@ -212,13 +214,13 @@ export async function createConfiguration( }), // this slow down performance for rspack !rspack && - flags.sourceMapHideFrameworks !== false && - new DevtoolsIgnorePlugin({ - shouldIgnorePath: (path) => { - if (path.includes('masknet') || path.includes('dimensiondev')) return false - return path.includes('/node_modules/') || path.includes('/webpack/') - }, - }), + flags.sourceMapHideFrameworks !== false && + new DevtoolsIgnorePlugin({ + shouldIgnorePath: (path) => { + if (path.includes('masknet') || path.includes('dimensiondev')) return false + return path.includes('/node_modules/') || path.includes('/webpack/') + }, + }), new (rspack?.ProvidePlugin || webpack.default.ProvidePlugin)({ // Widely used Node.js global variable Buffer: [require.resolve('buffer'), 'Buffer'], @@ -237,6 +239,7 @@ export async function createConfiguration( SOLANA_DEFAULT_RPC_URL: process.env.SOLANA_DEFAULT_RPC_URL || '', MASK_ENABLE_EXCHANGE: process.env.MASK_ENABLE_EXCHANGE || '', GOOGLE_CLIENT_ID: JSON.stringify(process.env.GOOGLE_CLIENT_ID) || '', + LOAD_KEY: process.env.LOAD_KEY || '', }), new (rspack?.DefinePlugin || webpack.default.DefinePlugin)({ 'process.browser': 'true', @@ -247,11 +250,11 @@ export async function createConfiguration( 'process.stderr': '/* stdin */ null', }), flags.reactRefresh && - new ( - await (rspack ? - import('@rspack/plugin-react-refresh') - : import('@pmmmwh/react-refresh-webpack-plugin')) - ).default({ overlay: false, esModule: true }), + new ( + await (rspack ? + import('@rspack/plugin-react-refresh') + : import('@pmmmwh/react-refresh-webpack-plugin')) + ).default({ overlay: false, esModule: true }), flags.profiling && new ProfilingPlugin(), // TODO: crashes rspack !rspack && new TrustedTypesPlugin(), @@ -274,14 +277,14 @@ export async function createConfiguration( from: productionLike ? require.resolve('webextension-polyfill/dist/browser-polyfill.min.js') - : require.resolve('webextension-polyfill/dist/browser-polyfill.js'), + : require.resolve('webextension-polyfill/dist/browser-polyfill.js'), to: join(polyfillFolder, 'browser-polyfill.js'), }, { from: productionLike ? require.resolve('../../../node_modules/ses/dist/lockdown.umd.min.js') - : require.resolve('../../../node_modules/ses/dist/lockdown.umd.js'), + : require.resolve('../../../node_modules/ses/dist/lockdown.umd.js'), to: join(polyfillFolder, 'lockdown.js'), }, { @@ -314,8 +317,8 @@ export async function createConfiguration( chunkIds: productionLike ? rspack ? 'deterministic' - : 'total-size' - : 'named', + : 'total-size' + : 'named', concatenateModules: productionLike, flagIncludedChunks: productionLike, mangleExports: false, @@ -358,8 +361,8 @@ export async function createConfiguration( return ( entry.name === 'backgroundWorker' ? rspack ? 'runtime_' + entry.name - : (false as any as string) - : 'runtime' + : (false as any as string) + : 'runtime' ) }, }, @@ -396,7 +399,7 @@ export async function createConfiguration( devtoolModuleFilenameTemplate: productionLike ? 'webpack://[namespace]/[resource-path]' - : join(import.meta.dirname, '../../../[resource-path]'), + : join(import.meta.dirname, '../../../[resource-path]'), globalObject: 'globalThis', publicPath: '/', clean: flags.mode === 'production', @@ -405,7 +408,7 @@ export async function createConfiguration( { policyName: 'webpack', } - : undefined, + : undefined, }, ignoreWarnings: [ /Failed to parse source map/, diff --git a/packages/plugins/FileService/src/Worker/load.ts b/packages/plugins/FileService/src/Worker/load.ts index d5593945cc8..dc0cbd7b298 100644 --- a/packages/plugins/FileService/src/Worker/load.ts +++ b/packages/plugins/FileService/src/Worker/load.ts @@ -5,8 +5,10 @@ import { LANDING_PAGE, Provider } from '../constants.js' import type { ProviderAgent, LandingPageMetadata, AttachmentOptions } from '../types.js' import { makeFileKeySigned } from '../helpers.js' +const LOAD_LEGACY_GATEWAY_URL = 'https://load0.network/download' const LOAD_GATEWAY_URL = 'https://load-s3-agent.load.network' const LOAD_UPLOAD_ENDPOINT = 'https://load-s3-agent.load.network/upload' +const LEGACY_ID_REGEX = /^0x[a-f0-9]{64}$/i class LoadAgent implements ProviderAgent { static providerName = 'Load Network' @@ -50,7 +52,11 @@ class LoadAgent implements ProviderAgent { async uploadLandingPage(metadata: LandingPageMetadata) { this.init() - const linkPrefix = LOAD_GATEWAY_URL + // decide which gateway URL to use based on ID + const linkPrefix = LEGACY_ID_REGEX.test(metadata.txId) + ? LOAD_LEGACY_GATEWAY_URL + : LOAD_GATEWAY_URL + const encodedMetadata = JSON.stringify({ name: metadata.name, size: metadata.size, @@ -59,6 +65,7 @@ class LoadAgent implements ProviderAgent { signed: await makeFileKeySigned(metadata.key), createdAt: new Date().toISOString(), }) + const response = await fetch(LANDING_PAGE) const text = await response.text() const replaced = text @@ -73,32 +80,36 @@ class LoadAgent implements ProviderAgent { async makePayload(data: Uint8Array, type: string, fileName: string = 'file.dat') { this.init() + try { + const blob = new Blob([data], { type }) + const formData = new FormData() + formData.append('file', blob) + formData.append('content_type', type) + formData.append('app_name', 'Maskbook') - const blob = new Blob([data], { type }) - const formData = new FormData() - formData.append('file', blob) - formData.append('content_type', type) - formData.append('app_name', 'Maskbook') - - const response = await fetch(LOAD_UPLOAD_ENDPOINT, { - method: 'POST', - headers: { - Authorization: `Bearer ${process.env.LOAD_NETWORK_KEY}`, - }, - body: formData, - signal: this.uploadController?.signal, - }) + const response = await fetch(LOAD_UPLOAD_ENDPOINT, { + method: 'POST', + headers: { + 'Authorization': `Bearer maskMASKhbs3` + }, + body: formData, + signal: this.uploadController?.signal + }) - if (!response.ok) { - throw new Error(`Upload failed: ${response.statusText}`) - } + if (!response.ok) { + throw new Error(`Upload failed: ${response.statusText}`) + } - const result = await response.json() - if (!result.success || !result.dataitem_id) { - throw new Error('Invalid response from upload service') - } + const result = await response.json() + if (!result.success || !result.dataitem_id) { + throw new Error('Invalid response from upload service') + } - return result.dataitem_id + return result.dataitem_id + } + catch (error) { + throw error + } } } diff --git a/packages/plugins/FileService/src/constants.ts b/packages/plugins/FileService/src/constants.ts index 77bb50e7053..9a09f5d424e 100644 --- a/packages/plugins/FileService/src/constants.ts +++ b/packages/plugins/FileService/src/constants.ts @@ -3,7 +3,7 @@ export const META_KEY_2 = 'com.maskbook.fileservice:2' export const META_KEY_3 = 'com.maskbook.fileservice:3' export const MAX_FILE_SIZE = 10 * 1000 * 1000 -export const MAX_FILE_SIZE_LOAD = 100 * 1024 * 1024 +export const MAX_FILE_SIZE_LOAD = 30 * 1024 * 1024 export const LANDING_PAGE = 'https://files.r2d2.to/partner/arweave/landing-page.html' export const RECOVERY_PAGE = 'https://fileservice.r2d2.to/recover' diff --git a/packages/plugins/FileService/src/helpers.ts b/packages/plugins/FileService/src/helpers.ts index 454d0482cf3..0cfcfe828a4 100644 --- a/packages/plugins/FileService/src/helpers.ts +++ b/packages/plugins/FileService/src/helpers.ts @@ -13,6 +13,10 @@ import schemaV1 from './schema-v1.json' with { type: 'json' } import schemaV2 from './schema-v2.json' with { type: 'json' } import schemaV3 from './schema-v3.json' with { type: 'json' } +// Load legacy detection + gateway +export const LOAD_LEGACY_ID_REGEX = /^0x[a-f0-9]{64}$/iu +export const LOAD_LEGACY_GATEWAY_URL = 'https://load0.network/download' + // Note: if the latest version has been changed, please update packages/mask/content-script/components/CompositionDialog/useSubmit.ts const reader_v1 = createTypedMessageMetadataReader(META_KEY_1, schemaV1) const reader_v2 = createTypedMessageMetadataReader(META_KEY_2, schemaV2) @@ -61,7 +65,12 @@ export function makeFileKey(length = 16) { } export function downloadFile(file: FileInfo) { - const gateway = resolveGatewayAPI(file.provider) + let gateway = resolveGatewayAPI(file.provider) + + if (file.provider === Provider.Load && LOAD_LEGACY_ID_REGEX.test(String(file.landingTxID ?? ''))) { + gateway = LOAD_LEGACY_GATEWAY_URL + } + let link = urlcat(gateway, '/:txId', { txId: file.landingTxID }) if (isAfter(new Date(2022, 8, 1), new Date(file.createdAt))) { link = urlcat(RECOVERY_PAGE, {