Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
cc24f30
try to support ipfs and swarm
lljxx1 Dec 14, 2021
83ec2db
add ipfs and swarm provider
lljxx1 Dec 14, 2021
8daaa0e
support ipfs and swarm
lljxx1 Dec 15, 2021
79042c3
add ipfs and swarm
lljxx1 Dec 15, 2021
565cfa0
fix
lljxx1 Dec 15, 2021
5c79b3c
change
lljxx1 Dec 15, 2021
ad8b431
fix
lljxx1 Dec 15, 2021
3d5156b
change
lljxx1 Dec 16, 2021
307986d
fix bee-js type error
lljxx1 Dec 16, 2021
38caea5
fix bee-js type error
lljxx1 Dec 16, 2021
727d1ec
fix i18n error
lljxx1 Dec 16, 2021
d10d4cd
hidden Meson CDN button when provider is not arweave
lljxx1 Dec 16, 2021
9785e8f
fix lint error
lljxx1 Dec 16, 2021
e825a03
fix spell check error
lljxx1 Dec 16, 2021
44f07f8
fix lint error
lljxx1 Dec 16, 2021
97f524c
fix lint error
lljxx1 Dec 16, 2021
248451a
refactor: provider agent
lljxx1 Dec 16, 2021
f523881
refactor: provider agent
lljxx1 Dec 16, 2021
233c2bf
refactor: provider agent
lljxx1 Dec 16, 2021
44a59df
refactor: provider agent
lljxx1 Dec 16, 2021
7fa1b6c
refactor: typo key cast
lljxx1 Dec 17, 2021
29b495f
eslint fix
lljxx1 Dec 17, 2021
48eba67
fix: spell error
lljxx1 Dec 21, 2021
faa68b5
fix: spell error
lljxx1 Dec 21, 2021
b9480d1
fix: revert cspell.json
lljxx1 Dec 21, 2021
91e60fb
fix: add comment, use lodash
lljxx1 Dec 21, 2021
f4bd0ad
fix: change
lljxx1 Dec 22, 2021
4415e4a
fix: change
lljxx1 Dec 22, 2021
9676aeb
fix: lint error
lljxx1 Dec 23, 2021
36b9fc8
chore: merge with main
Jack-Works Dec 24, 2021
1489916
chore: more patch
Jack-Works Dec 24, 2021
dd48d7b
chore: more patch
Jack-Works Dec 24, 2021
e1201a0
fix: remove duplicate checkbox
lljxx1 Dec 27, 2021
4d7e7fb
refactor: delay initialization
lljxx1 Dec 28, 2021
f1a5a0d
fix: add provider to metadata
lljxx1 Jan 11, 2022
63094e3
refactor: using createLookupTableResolver
lljxx1 Jan 12, 2022
8548edb
fix: typo
lljxx1 Jan 12, 2022
a409a45
refactor: remove unuse code
lljxx1 Jan 12, 2022
16c6d74
Merge branch 'develop' into develop
lljxx1 Jan 18, 2022
51e636d
fix: update frozen-lockfile
lljxx1 Jan 19, 2022
ae59a63
Merge branch 'develop' of https://github.com/lljxx1/Maskbook into dev…
lljxx1 Jan 19, 2022
dff44bd
fix: update frozen-lockfile
lljxx1 Jan 19, 2022
7a41bcc
fix lint errors
lljxx1 Jan 22, 2022
64f429a
Merge branch 'develop' into develop
Tedko Feb 2, 2022
1dc9095
Update pnpm-lock.yaml
Tedko Feb 2, 2022
a6da8b7
fix: pnpm-lock
lljxx1 Feb 5, 2022
bdb49a1
Merge branch 'develop' of https://github.com/lljxx1/Maskbook into dev…
lljxx1 Feb 5, 2022
f28b450
fix: pnpm no-frozen-lockfile
lljxx1 Feb 5, 2022
c0e5123
fix: lint error
lljxx1 Feb 6, 2022
d0c5d02
fix: import JWKInterface from arweave directly
lljxx1 Feb 6, 2022
61d76e7
Merge branch 'develop' into develop
lljxx1 Feb 7, 2022
091f7e7
Merge remote-tracking branch 'upstream/develop' into develop
lljxx1 Feb 9, 2022
a8caf7e
fix: update
lljxx1 Feb 9, 2022
daa5f03
fix: update
lljxx1 Feb 9, 2022
50037eb
fix: update
lljxx1 Feb 9, 2022
18b0f9c
fix: update
lljxx1 Feb 9, 2022
385029d
fix: update
lljxx1 Feb 9, 2022
898ff5b
chore: try fix lockfile
Jack-Works Feb 9, 2022
7240ba6
fix: update color
lljxx1 Feb 10, 2022
85ac042
fix: listen dialog close
lljxx1 Feb 10, 2022
f379eff
fix: lint error
lljxx1 Feb 10, 2022
1545b5c
fix: text color, button width
lljxx1 Feb 11, 2022
7931964
fix: text color, button width
lljxx1 Feb 11, 2022
4421174
fix: text color, button width
lljxx1 Feb 11, 2022
63b4fe5
fix: text color, button width
lljxx1 Feb 11, 2022
f77cd14
fix: rename
lljxx1 Feb 11, 2022
8d3c58a
Merge branch 'develop' into develop
lljxx1 Feb 13, 2022
726185d
fix: update pnpm-lock
lljxx1 Feb 14, 2022
1d1a5be
fix: add webpack rule esm module fully specified false
lljxx1 Feb 14, 2022
0771b64
fix: limit specify package
lljxx1 Feb 14, 2022
0a20950
Merge branch 'develop' into develop
lljxx1 Feb 15, 2022
2a1ffb5
chore: update broken package
Jack-Works Feb 16, 2022
30beac9
chore: update broken package
Jack-Works Feb 16, 2022
2ce7aea
chore: merge with main
Jack-Works Feb 16, 2022
d52da43
Merge branch 'develop' into develop
guanbinrui Feb 21, 2022
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: 2 additions & 0 deletions .pnpmfile.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const approvedList = new Map([
['html-parse-stringify2', 'github:locize/html-parse-stringify2'],
/* cspell:disable-next-line */
['async-eventemitter', 'github:ahultgren/async-eventemitter#fa06e39e56786ba541c180061dbf2c0a5bbf951c'],
// Introduced by ipfs-utils
['node-fetch', 'https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz'],
Comment thread
Tedko marked this conversation as resolved.
])

/**
Expand Down
2 changes: 2 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"elec",
"encryptedmsg",
"endregion",
"ethersphere",
"ethersproject",
"eustatius",
"everytime",
Expand Down Expand Up @@ -106,6 +107,7 @@
"imtokenv2",
"investables",
"ipfs",
"IPFSHTTP",
"ipfsurl",
"ittr",
"jailbroken",
Expand Down
4 changes: 4 additions & 0 deletions packages/plugins/FileService/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
"types": "./dist/index.d.ts",
"dependencies": {
"@dimensiondev/common-protocols": "1.6.0-20210723072221-8f46a92",
"@ethersphere/bee-js": "^3.3.1",
"@masknet/icons": "workspace:*",
"@masknet/plugin-infra": "workspace:*",
"@masknet/plugin-wallet": "workspace:*",
"@masknet/shared": "workspace:*",
"@masknet/shared-base": "workspace:*",
"@masknet/theme": "workspace:*",
"@msgpack/msgpack": "^2.7.2",
"@masknet/web3-kit": "workspace:*",
"arweave": "^1.10.3",
"ipfs-http-client": "^54.0.2",
"urlcat": "^2.0.4",
"date-fns": "^2.28.0",
"react-feather": "^2.0.9",
"react-router-dom": "5",
Expand Down
20 changes: 18 additions & 2 deletions packages/plugins/FileService/src/SNSAdaptor/MainDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { WalletMessages } from '@masknet/plugin-wallet'
import { Entry } from './components'
import { META_KEY_2 } from '../constants'
import { Exchange } from './hooks/Exchange'
import type { FileInfo } from '../types'
import type { FileInfo, DialogCloseCallback } from '../types'
import { useCompositionContext } from '@masknet/plugin-infra'

interface Props {
Expand Down Expand Up @@ -62,21 +62,37 @@ const FileServiceDialog: React.FC<Props> = (props) => {
closeWalletStatusDialog()
props.onClose()
}

let onDialogCloseCallback: DialogCloseCallback | null
const callDialogClose = () => {
try {
onDialogCloseCallback?.()
} catch (error) {}
onDialogCloseCallback = null
}

const onDecline = () => {
if (onDialogCloseCallback) {
callDialogClose()
return
}
if (!uploading) {
props.onClose()
return
}
showSnackbar(t.uploading_on_cancel())
}
const onDialogClose = (cb: DialogCloseCallback) => {
onDialogCloseCallback = cb
}
return (
<MaskDialog
DialogProps={{ scroll: 'paper', classes: { paper: classes.paper } }}
open={props.open}
title={t.__display_name()}
onClose={onDecline}>
<DialogContent>
<Exchange onUploading={setUploading} onInsert={setSelectedFileInfo}>
<Exchange onDialogClose={onDialogClose} onUploading={setUploading} onInsert={setSelectedFileInfo}>
<Entry />
</Exchange>
</DialogContent>
Expand Down
7 changes: 6 additions & 1 deletion packages/plugins/FileService/src/SNSAdaptor/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { DownloadCloud, File } from 'react-feather'
import { useI18N } from '../locales/i18n_generated'
import { CopyableCode } from './components/Copyable'
import type { FileInfo } from '../types'
import { resolveGatewayAPI } from '../helpers'
import urlcat from 'urlcat'

const useStyles = makeStyles()((theme) => ({
root: {
Expand Down Expand Up @@ -55,7 +57,10 @@ export function Preview({ info }: { info: FileInfo }) {
{t.unencrypted()}
</Typography>
)
const link = `https://arweave.net/${info.landingTxID}`

const linkPrefix = resolveGatewayAPI(info.provider)
const link = urlcat(linkPrefix, '/:txId', { txId: info.landingTxID })

const onClick = (event: React.MouseEvent) => {
event.preventDefault()
event.stopPropagation()
Expand Down
61 changes: 49 additions & 12 deletions packages/plugins/FileService/src/SNSAdaptor/components/Upload.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { Attachment } from '@dimensiondev/common-protocols'
import { blobToArrayBuffer, encodeArrayBuffer } from '@dimensiondev/kit'
import { Checkbox, FormControlLabel, Link, Typography } from '@mui/material'
import { Checkbox, Radio, FormControlLabel, Link, Typography } from '@mui/material'
import { makeStyles } from '@masknet/theme'
import { isNil } from 'lodash-unified'
import { useState } from 'react'
import { useHistory } from 'react-router-dom'
import { useAsync } from 'react-use'
import { useI18N, Translate } from '../../locales/i18n_generated'
import { makeFileKey } from '../../file-key'
import type { ProviderConfig } from '../../types'
import { FileRouter, MAX_FILE_SIZE } from '../../constants'
import { PluginFileServiceRPC } from '../../Worker/rpc'
import { RecentFiles } from './RecentFiles'
import { UploadDropArea } from './UploadDropArea'
import { Provider } from '../../types'

const useStyles = makeStyles()((theme) => ({
container: {
Expand Down Expand Up @@ -57,7 +59,23 @@ export const Upload: React.FC = () => {
const history = useHistory()
const [encrypted, setEncrypted] = useState(true)
const [useCDN, setUseCDN] = useState(false)
const [provider, setProvider] = useState<Provider>(Provider.arweave)
const recent = useAsync(() => PluginFileServiceRPC.getRecentFiles(), [])
const allProviders: ProviderConfig[] = [
{
provider: Provider.arweave,
name: t.provider_arweave(),
},
{
provider: Provider.ipfs,
name: t.provider_ipfs(),
},
{
provider: Provider.swarm,
name: t.provider_swarm(),
},
]

const onFile = async (file: File) => {
let key: string | undefined = undefined
if (encrypted) {
Expand All @@ -75,11 +93,39 @@ export const Upload: React.FC = () => {
block,
checksum,
useCDN,
provider,
})
} else {
history.replace(FileRouter.uploaded, item)
}
}

const allProviderOptions = allProviders.map((config: ProviderConfig) => (
<FormControlLabel
key={config.provider}
control={
<Radio
color="primary"
checked={provider === config.provider}
onChange={() => setProvider(config.provider)}
/>
}
className={classes.encrypted}
label={config.name}
/>
))

const cdnButton =
provider === Provider.arweave ? (
<FormControlLabel
control={
<Checkbox color="primary" checked={useCDN} onChange={(event) => setUseCDN(event.target.checked)} />
}
className={classes.usedCDN}
label={t.use_cdn()}
/>
) : null

return (
<section className={classes.container}>
<section className={classes.upload}>
Expand All @@ -98,18 +144,9 @@ export const Upload: React.FC = () => {
className={classes.encrypted}
label={t.on_encrypt_it()}
/>
<FormControlLabel
control={
<Checkbox
color="primary"
checked={useCDN}
onChange={(event) => setUseCDN(event.target.checked)}
/>
}
className={classes.usedCDN}
label={t.use_cdn()}
/>
{cdnButton}
</section>
<section className={classes.checkItems}>{allProviderOptions}</section>
<section className={classes.legal}>
<Typography className={classes.legalText}>
<Translate.legal_text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const useStyles = makeStyles()((theme) => ({
here: {
fontSize: 12,
lineHeight: 2.5,
color: theme.palette.grey[100],
color: theme.palette.mode === 'dark' ? theme.palette.grey[100] : theme.palette.grey[500],
userSelect: 'none',
},
hint: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { useI18N } from '../../locales/i18n_generated'
import { FileRouter } from '../../constants'
import type { FileInfo } from '../../types'
import { FileName } from './FileName'
import { resolveGatewayAPI } from '../../helpers'
import urlcat from 'urlcat'

const useStyles = makeStyles()({
container: {
Expand Down Expand Up @@ -41,6 +43,14 @@ const useStyles = makeStyles()({
flexDirection: 'column',
justifyContent: 'center',
},
change: {
fontSize: 14,
margin: '0 auto',
display: 'flex',
padding: '0 60px',
flexDirection: 'column',
justifyContent: 'center',
},
info: {
margin: 0,
},
Expand All @@ -50,7 +60,7 @@ export const Uploaded: React.FC = () => {
const t = useI18N()
const { classes } = useStyles()
const history = useHistory()
const { onInsert } = useExchange()
const { onInsert, onDialogClose } = useExchange()
const { state } = useLocation<FileInfo>()
useEffect(() => {
onInsert(state)
Expand All @@ -59,14 +69,19 @@ export const Uploaded: React.FC = () => {
onInsert(null)
history.replace(FileRouter.upload)
}

// return upload route
onDialogClose(onBack)
const onPreview = (event: React.MouseEvent) => {
// ! THIS METHOD IS ONLY IN THE DEBUGGER !
// ! Trigger: [Shift Key] + [Click] !
// see https://mdn.io/shiftKey
if (!event.shiftKey) {
return
}
const link = `https://arweave.net/${state.landingTxID}`

const linkPrefix = resolveGatewayAPI(state.provider)
const link = urlcat(linkPrefix, '/:txId', { txId: state.landingTxID })
open(state.key ? `${link}#${state.key}` : link)
}
return (
Expand All @@ -82,10 +97,10 @@ export const Uploaded: React.FC = () => {
<span>{' '}</span>
<span>{formatDateTime(state.createdAt, 'yyyy-MM-dd HH:mm:ss')}</span>
</p>
<Button onClick={onBack} variant="contained">
{t.on_change_file()}
</Button>
</Typography>
<Button className={classes.change} onClick={onBack} variant="contained">
{t.on_change_file()}
</Button>
</Grid>
</Grid>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useAsync } from 'react-use'
import { useI18N } from '../../locales/i18n_generated'
import { timeout } from '@masknet/shared-base'
import { FileRouter } from '../../constants'
import type { FileInfo } from '../../types'
import type { FileInfo, Provider } from '../../types'
import { PluginFileServiceRPC, PluginFileServiceRPCGenerator } from '../../Worker/rpc'
import { useExchange } from '../hooks/Exchange'
import { FileName } from './FileName'
Expand Down Expand Up @@ -42,6 +42,7 @@ interface RouteState {
block: Uint8Array
checksum: string
useCDN: boolean
provider: Provider
}

export const Uploading: React.FC = () => {
Expand All @@ -58,20 +59,22 @@ export const Uploading: React.FC = () => {
return () => onUploading(false)
}, [onUploading])
const { error } = useAsync(async () => {
const currentProvider = state.provider as Provider
const payloadTxID = await timeout(
PluginFileServiceRPC.makeAttachment({
PluginFileServiceRPC.makeAttachment(currentProvider, {
name: state.name,
key: state.key,
block: state.block,
type: state.type,
}),
60000, // = 1 minute
)
setPreparing(false)
for await (const pctComplete of PluginFileServiceRPCGenerator.upload(payloadTxID)) {
for await (const pctComplete of PluginFileServiceRPCGenerator.upload(currentProvider, payloadTxID)) {
setSendSize(state.size * (pctComplete / 100))
}
const landingTxID = await timeout(
PluginFileServiceRPC.uploadLandingPage({
PluginFileServiceRPC.uploadLandingPage(currentProvider, {
name: state.name,
size: state.size,
txId: payloadTxID,
Expand All @@ -83,9 +86,8 @@ export const Uploading: React.FC = () => {
)
const item: FileInfo = {
type: 'file',
provider: 'arweave',
provider: currentProvider,
id: state.checksum,

name: state.name,
size: state.size,
createdAt: new Date(startedAt),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { noop, omit } from 'lodash-unified'
import { createContext, useContext } from 'react'
import type { FileInfo } from '../../types'
import type { FileInfo, DialogCloseCallback } from '../../types'

export interface Props {
onInsert(info: FileInfo | null): void
onUploading(enabled: boolean): void
onDialogClose(cb: DialogCloseCallback): void
}

const Context = createContext<Props>({
onInsert: noop,
onUploading: noop,
onDialogClose: noop,
})

export const Exchange: React.FC<Props> = (props) => (
Expand Down
Loading