-
Notifications
You must be signed in to change notification settings - Fork 527
Expand file tree
/
Copy pathconsts.js
More file actions
181 lines (172 loc) · 5.25 KB
/
consts.js
File metadata and controls
181 lines (172 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
export const IS_MAC = navigator.userAgent.indexOf('Mac') !== -1
/**
* @typedef {import('./protocol').Message} Message
* @typedef {import('./protocol').Model} Model
*/
export const ACTIONS = {
/** @type {'FILES_FETCH'} */
FETCH: ('FILES_FETCH'),
/** @type {'FILES_MOVE'} */
MOVE: ('FILES_MOVE'),
/** @type {'FILES_COPY'} */
COPY: ('FILES_COPY'),
/** @type {'FILES_DELETE'} */
DELETE: ('FILES_DELETE'),
/** @type {'FILES_MAKEDIR'} */
MAKE_DIR: ('FILES_MAKEDIR'),
/** @type {'FILES_WRITE'} */
WRITE: ('FILES_WRITE'),
/** @type {'FILES_DOWNLOADLINK'} */
DOWNLOAD_LINK: ('FILES_DOWNLOADLINK'),
/** @type {'FILES_SHARE_LINK'} */
SHARE_LINK: ('FILES_SHARE_LINK'),
/** @type {'FILES_ADDBYPATH'} */
ADD_BY_PATH: ('FILES_ADDBYPATH'),
/** @type {'FILES_ADD_CAR'} */
ADD_CAR_FILE: ('FILES_ADD_CAR'),
/** @type {'FILES_BULK_CID_IMPORT'} */
BULK_CID_IMPORT: ('FILES_BULK_CID_IMPORT'),
/** @type {'FILES_SYNC_FROM_PINS'} */
SYNC_FROM_PINS: ('FILES_SYNC_FROM_PINS'),
/** @type {'FILES_PIN_ADD'} */
PIN_ADD: ('FILES_PIN_ADD'),
/** @type {'FILES_PIN_REMOVE'} */
PIN_REMOVE: ('FILES_PIN_REMOVE'),
/** @type {'FILES_PIN_LIST'} */
PIN_LIST: ('FILES_PIN_LIST'),
/** @type {'FILES_SIZE_GET'} */
SIZE_GET: ('FILES_SIZE_GET'),
/** @type {'FILES_DISMISS_ERRORS'} */
DISMISS_ERRORS: ('FILES_DISMISS_ERRORS'),
/** @type {'FILES_CLEAR_ALL'} */
CLEAR_ALL: ('FILES_CLEAR_ALL'),
/** @type {'FILES_WRITE_UPDATED'} */
WRITE_UPDATED: ('FILES_WRITE_UPDATED'),
/** @type {'FILES_UPDATE_SORT'} */
UPDATE_SORT: ('FILES_UPDATE_SORT'),
/** @type {'FILES_READ'} */
READ_FILE: ('FILES_READ')
}
export const SORTING = {
/** @type {'name'} */
BY_NAME: ('name'),
/** @type {'size'} */
BY_SIZE: ('size'),
/** @type {'pinned'} */
BY_PINNED: ('pinned'),
/** @type {'original'} */
BY_ORIGINAL: ('original')
}
export const IGNORED_FILES = [
'.DS_Store',
'thumbs.db',
'desktop.ini'
]
// Maximum length for DNS labels (used for subdomain gateway CID validation)
export const DNS_LABEL_MAX_LENGTH = 63
/** @type {Model} */
export const DEFAULT_STATE = {
pageContent: null,
mfsSize: -1,
pins: [],
sorting: (() => {
// Try to read from localStorage, fallback to default
try {
const saved = window.localStorage?.getItem('files.sorting')
if (saved) {
const parsed = JSON.parse(saved)
// Validate the structure and values
const validSortBy = Object.values(SORTING).includes(parsed?.by)
const validAsc = typeof parsed?.asc === 'boolean'
if (parsed && validSortBy && validAsc) {
return parsed
}
}
} catch (error) {
console.warn('Failed to read files.sorting from localStorage:', error)
// Clear corrupted data
try {
window.localStorage?.removeItem('files.sorting')
} catch {}
}
return {
by: SORTING.BY_NAME,
asc: true
}
})(),
pending: [],
finished: [],
failed: []
}
export const cliCmdKeys = {
DOWNLOAD_OBJECT_COMMAND: 'downloadObjectCommand',
REMOVE_FILE_FROM_IPFS: 'removeFileFromIpfs',
UPDATE_IPFS_CONFIG: 'updateIpfsConfig',
PIN_OBJECT: 'pinObject',
RENAME_IPFS_OBJECT: 'renameObject',
ADD_FILE: 'addNewFile',
ADD_DIRECTORY: 'addNewDirectory',
CREATE_NEW_DIRECTORY: 'createNewDirectory',
FROM_IPFS: 'fromIpfs',
FROM_CAR: 'fromCar',
ADD_NEW_PEER: 'addNewPeer',
PUBLISH_WITH_IPNS: 'publishWithIPNS',
DOWNLOAD_CAR_COMMAND: 'downloadCarCommand'
}
export const cliCmdPrefixes = {
PIN_OBJECT: 'ipfs pin'
}
export const cliCommandList = {
[cliCmdKeys.UPDATE_IPFS_CONFIG]: () => 'ipfs config replace <path-to-settings.json>',
/**
* @param {string} filePath
*/
[cliCmdKeys.REMOVE_FILE_FROM_IPFS]: (filePath) => `ipfs files rm -r "${filePath}"`,
/**
* @param {string} cid
*/
[cliCmdKeys.DOWNLOAD_OBJECT_COMMAND]: (cid) => `ipfs get ${cid}`,
/**
* @param {string} cid
* @param {string} op
*/
[cliCmdKeys.PIN_OBJECT]: (cid, op) => `${cliCmdPrefixes.PIN_OBJECT} ${op} ${cid}`,
/**
* @param {string} filePath
* @param {string} fileName
*/
[cliCmdKeys.RENAME_IPFS_OBJECT]: (filePath, fileName) => {
const prefix = filePath.replace(fileName, '').trim()
return `ipfs files mv "${filePath}" "${prefix}<new-name>"`
},
/**
* @param {string} path
*/
[cliCmdKeys.ADD_FILE]: (path) => `ipfs files cp /ipfs/$(ipfs add -Q <local-file>) "${path}/<dest-name>"`,
/**
* @param {string} path
*/
[cliCmdKeys.ADD_DIRECTORY]: (path) => `ipfs files cp /ipfs/$(ipfs add -r -Q <local-folder>) "${path}/<dest-name>"`,
/**
* @param {string} path
*/
[cliCmdKeys.CREATE_NEW_DIRECTORY]: (path) => `ipfs files mkdir "${path}/<folder-name>"`,
/**
* @param {string} path
*/
[cliCmdKeys.FROM_IPFS]: (path) => `ipfs files cp /ipfs/<cid> "${path}/<dest-name>"`,
/**
* @param {string} path
*/
[cliCmdKeys.FROM_CAR]: (path) => `ipfs dag import file.car && ipfs files cp /ipfs/<imported-cid> "${path}/<dest-name>"`,
[cliCmdKeys.ADD_NEW_PEER]: () => 'ipfs swarm connect <peer-multiaddr>',
/**
* @param {string} ipfsPath
* @param {string} name
*/
[cliCmdKeys.PUBLISH_WITH_IPNS]: (ipfsPath, name) => `ipfs name publish ${ipfsPath} --key="${name}"`,
/**
* @param {string} cid
*/
[cliCmdKeys.DOWNLOAD_CAR_COMMAND]: (cid) => `ipfs dag export ${cid}`
}