@@ -3,27 +3,29 @@ import { useDevToolsClient } from '~/logic/client'
3
3
import { rpc } from ' ~/logic/rpc'
4
4
5
5
const props = defineProps <{
6
- asset : AssetInfo
6
+ modelValue : AssetInfo
7
7
}>()
8
-
8
+ const emit = defineEmits <{ (... args : any ): void }>()
9
+ const asset = useVModel (props , ' modelValue' , emit , { passive: true })
10
+ const showNotification = useNotification ()
9
11
const origin = window .parent .location .origin
10
12
11
13
const imageMeta = computedAsync (() => {
12
- if (props . asset .type !== ' image' )
14
+ if (asset . value .type !== ' image' )
13
15
return undefined
14
- return rpc .getImageMeta (props . asset .filePath )
16
+ return rpc .getImageMeta (asset . value .filePath )
15
17
})
16
18
17
19
const textContent = computedAsync (() => {
18
- if (props . asset .type !== ' text' )
20
+ if (asset . value .type !== ' text' )
19
21
return undefined
20
- return rpc .getTextAssetContent (props . asset .filePath )
22
+ return rpc .getTextAssetContent (asset . value .filePath )
21
23
})
22
24
23
25
const copy = useCopy ()
24
- const timeago = useTimeAgo (() => props . asset .mtime )
26
+ const timeAgo = useTimeAgo (() => asset . value .mtime )
25
27
const fileSize = computed (() => {
26
- const size = props . asset .size
28
+ const size = asset . value .size
27
29
if (size < 1024 )
28
30
return ` ${size } B `
29
31
if (size < 1024 * 1024 )
@@ -51,9 +53,65 @@ const supportsPreview = computed(() => {
51
53
' text' ,
52
54
' video' ,
53
55
' font' ,
54
- ].includes (props . asset .type )
56
+ ].includes (asset . value .type )
55
57
})
56
58
59
+ const deleteDialog = ref (false )
60
+ async function deleteAsset() {
61
+ try {
62
+ await rpc .deleteStaticAsset (asset .value .filePath )
63
+ asset .value = undefined as any
64
+ deleteDialog .value = false
65
+ showNotification ({
66
+ text: ' Asset deleted' ,
67
+ icon: ' carbon-checkmark' ,
68
+ type: ' primary' ,
69
+ })
70
+ }
71
+ catch (error ) {
72
+ deleteDialog .value = false
73
+ showNotification ({
74
+ text: ' Something went wrong!' ,
75
+ icon: ' carbon-warning' ,
76
+ type: ' error' ,
77
+ })
78
+ }
79
+ }
80
+
81
+ const renameDialog = ref (false )
82
+ const newName = ref (' ' )
83
+ async function renameAsset() {
84
+ const parts = asset .value .filePath .split (' /' )
85
+ const oldName = parts .slice (- 1 )[0 ].split (' .' ).slice (0 , - 1 ).join (' .' )
86
+ if (! newName .value || newName .value === oldName ) {
87
+ return showNotification ({
88
+ text: ' Please enter a new name' ,
89
+ icon: ' carbon-warning' ,
90
+ type: ' error' ,
91
+ })
92
+ }
93
+ try {
94
+ const extension = parts .slice (- 1 )[0 ].split (' .' ).slice (- 1 )[0 ]
95
+ const fullPath = ` ${parts .slice (0 , - 1 ).join (' /' )}/${newName .value }.${extension } `
96
+ await rpc .renameStaticAsset (asset .value .filePath , fullPath )
97
+
98
+ asset .value = undefined as any
99
+ renameDialog .value = false
100
+ showNotification ({
101
+ text: ' Asset renamed' ,
102
+ icon: ' carbon-checkmark' ,
103
+ type: ' primary' ,
104
+ })
105
+ }
106
+ catch (error ) {
107
+ showNotification ({
108
+ text: ' Something went wrong!' ,
109
+ icon: ' carbon-warning' ,
110
+ type: ' error' ,
111
+ })
112
+ }
113
+ }
114
+
57
115
const client = useDevToolsClient ()
58
116
</script >
59
117
@@ -161,7 +219,7 @@ const client = useDevToolsClient()
161
219
<td w-30 ws-nowrap pr5 text-right op50 >
162
220
Last modified
163
221
</td >
164
- <td >{{ new Date(asset.mtime).toLocaleString() }} <span op70 >({{ timeago }})</span ></td >
222
+ <td >{{ new Date(asset.mtime).toLocaleString() }} <span op70 >({{ timeAgo }})</span ></td >
165
223
</tr >
166
224
</tbody >
167
225
</table >
@@ -174,11 +232,50 @@ const client = useDevToolsClient()
174
232
<div x-divider />
175
233
</div >
176
234
<div flex =" ~ gap2 wrap" >
177
- <VDButton :to =" `${origin}${asset.publicPath}`" download target =" _blank" icon =" carbon-download" >
235
+ <VDButton :to =" `${origin}${asset.publicPath}`" download target =" _blank" icon =" carbon-download" n = " green " >
178
236
Download
179
237
</VDButton >
238
+ <VDButton icon =" carbon-text-annotation-toggle" n =" blue" @click =" renameDialog = !renameDialog" >
239
+ Rename
240
+ </VDButton >
241
+ <VDButton icon =" carbon-delete" n =" red" @click =" deleteDialog = !deleteDialog" >
242
+ Delete
243
+ </VDButton >
180
244
</div >
181
245
182
246
<div flex-auto />
247
+
248
+ <VDDialog
249
+ v-model =" deleteDialog" @close =" deleteDialog = false"
250
+ >
251
+ <div flex =" ~ col gap-4" min-h-full w-full of-hidden p8 >
252
+ <span >
253
+ Are you sure you want to delete this asset?
254
+ </span >
255
+ <div flex =" ~ gap2 wrap justify-center" >
256
+ <VDButton icon =" carbon-close" @click =" deleteDialog = false" >
257
+ Cancel
258
+ </VDButton >
259
+ <VDButton icon =" carbon-delete" n =" red" @click =" deleteAsset" >
260
+ Delete
261
+ </VDButton >
262
+ </div >
263
+ </div >
264
+ </VDDialog >
265
+ <VDDialog
266
+ v-model =" renameDialog" @close =" deleteDialog = false"
267
+ >
268
+ <div flex =" ~ col gap-4" min-h-full w-full of-hidden p8 >
269
+ <VDTextInput v-model =" newName" placeholder =" New name" n =" blue" />
270
+ <div flex =" ~ gap2 wrap justify-center" >
271
+ <VDButton icon =" carbon-close" @click =" renameDialog = false" >
272
+ Cancel
273
+ </VDButton >
274
+ <VDButton icon =" carbon-text-annotation-toggle" n =" blue" @click =" renameAsset" >
275
+ Rename
276
+ </VDButton >
277
+ </div >
278
+ </div >
279
+ </VDDialog >
183
280
</div >
184
281
</template >
0 commit comments