Repository navigation
Expand file tree
/
Copy pathfileAPI.js
More file actions
139 lines (126 loc) · 3.04 KB
/
Copy pathfileAPI.js
File metadata and controls
139 lines (126 loc) · 3.04 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
import { request, qs } from '../utils'
import axios from 'axios'
import * as maskActions from 'components/Mask/actions'
export function fetchPath (path, order, group) {
return request.get(`/workspaces/${config.spaceKey}/files`, {
path,
order: true,
group: true
}).then((res) => {
return res.filter((item) => {
return !item.name.startsWith('.nfs000')
})
})
}
export function downloadFile (path, shouldPacked) {
let filePath = path || config.projectName || 'Home'
if (shouldPacked) {
filePath += '.tar.gz'
}
// if (config.isDefault) {
// filePath = 'Home.tar.gz'
// }
const packOrRaw = shouldPacked ? 'pack' : 'raw'
let url = `${config.baseURL}/workspaces/${config.spaceKey}/${packOrRaw}`
url += `?${qs.stringify({
path,
inline: false
})}`
// window.open(url, '_blank')
const downloadTimeout = setTimeout(() => {
maskActions.showMask({ message: i18n`file.preparingDownload`, countdown: 60 })
}, 600)
request.download(url, filePath.split('/').pop()).then((res) => {
clearTimeout(downloadTimeout)
maskActions.hideMask()
})
}
export function uploadFile (path, file, option) {
const formdata = new FormData()
formdata.append('path', path)
formdata.append('files', file, file.name)
request.upload(`${config.baseURL}/workspaces/${config.spaceKey}/upload`, formdata, {
onUploadProgress: option.onUploadProgress
}).catch((res) => {
option.onUploadFailed()
})
}
export function writeFile (path, content, base64) {
return request({
method: 'PUT',
url: `/workspaces/${config.spaceKey}/files`,
data: {
path,
content,
base64: base64 || false,
override: true,
createParent: true
}
})
}
export function readFile (path, encoding) {
const url = config.isPlatform ?
`/workspaces/${config.spaceKey}/read`
: `/workspaces/${config.spaceKey}/file/read`
return request.get(url, {
path,
base64: false,
encoding
})
}
export function createFile (path) {
return request({
method: 'POST',
url: `/workspaces/${config.spaceKey}/files`,
data: {
path
}
})
}
export function createFolder (path) {
return request({
method: 'POST',
url: `/workspaces/${config.spaceKey}/mkdir`,
data: {
path
}
})
}
export function moveFile (from, to, force = false) {
return request({
method: 'POST',
url: `/workspaces/${config.spaceKey}/move`,
data: {
from,
to,
force
}
})
}
export function deleteFile (path) {
return request({
method: 'DELETE',
url: `/workspaces/${config.spaceKey}/files`,
params: {
path,
recursive: true
}
})
}
export function searchFile (value, includeNonProjectItems = false) {
return request({
method: 'POST',
url: `/workspaces/${config.spaceKey}/search`,
data: {
keyword: value,
includeNonProjectItems
}
})
}
export function searchTxt (keyword) {
return request.post(`/workspaces/${config.spaceKey}/txt-search`, { keyword }, {
headers: {
'Content-Type': 'application/json',
}
})
}