Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
59 changes: 31 additions & 28 deletions packages/mask/.webpack/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -68,7 +70,7 @@ export async function createConfiguration(
experiments:
rspack ?
{ futureDefaults: true }
: {
: {
futureDefaults: true,
deferImport: true,
},
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -188,7 +190,7 @@ export async function createConfiguration(
dependency: 'url',
type: 'asset/resource',
}
: null,
: null,
],
},
plugins: [
Expand All @@ -202,7 +204,7 @@ export async function createConfiguration(
runChecks: true,
diagnosticsVerbosity: 1,
})
: undefined,
: undefined,
new WebExtensionPlugin({
background: { pageEntry: 'background', serviceWorkerEntry: 'backgroundWorker' },
experimental_output: {
Expand All @@ -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'],
Expand All @@ -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',
Expand All @@ -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(),
Expand All @@ -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'),
},
{
Expand Down Expand Up @@ -314,8 +317,8 @@ export async function createConfiguration(
chunkIds:
productionLike ?
rspack ? 'deterministic'
: 'total-size'
: 'named',
: 'total-size'
: 'named',
concatenateModules: productionLike,
flagIncludedChunks: productionLike,
mangleExports: false,
Expand Down Expand Up @@ -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'
)
},
},
Expand Down Expand Up @@ -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',
Expand All @@ -405,7 +408,7 @@ export async function createConfiguration(
{
policyName: 'webpack',
}
: undefined,
: undefined,
},
ignoreWarnings: [
/Failed to parse source map/,
Expand Down
57 changes: 34 additions & 23 deletions packages/plugins/FileService/src/Worker/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/FileService/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
11 changes: 10 additions & 1 deletion packages/plugins/FileService/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileInfoV1>(META_KEY_1, schemaV1)
const reader_v2 = createTypedMessageMetadataReader<FileInfo>(META_KEY_2, schemaV2)
Expand Down Expand Up @@ -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, {
Expand Down
Loading