-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathroutes.js
70 lines (57 loc) · 2.48 KB
/
routes.js
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
'use strict'
const Route = use('Route')
const Drive = use('Drive')
Route.post('gcs', async ({ request, response }) => {
const file = request.file('image')
const url = await Drive.disk('gcs').put(file.clientName, file.tmpPath)
response.send({ url: url })
// if the file is publicly accessible, add options { public: true }
// const url = await Drive.disk('gcs').put(file.clientName, file.tmpPath, { public: true })
})
Route.get('gcs/:filename/exists', async ({ params, response }) => {
const filename = params.filename
const exists = await Drive.disk('gcs').exists(filename)
response.send({ exists: exists })
})
Route.get('gcs/:filename/url', async ({ params, response }) => {
const filename = params.filename
const url = await Drive.disk('gcs').getUrl(filename)
response.send({ url: url })
})
Route.get('gcs/:filename/signUrl', async ({ params, response }) => {
const filename = params.filename
const signedUrl = await Drive.disk('gcs').getSignedUrl(filename, '05-05-2018')
response.send({ signedUrl: signedUrl })
})
Route.get('gcs/:filename/object', async ({ params, response }) => {
const filename = params.filename
const object = await Drive.disk('gcs').getObject(filename)
response.send(object)
})
Route.get('gcs/:filename/download', async ({ params, response }) => {
const filename = params.filename
const path = await Drive.disk('gcs').download(filename)
response.send({ path: path })
})
Route.delete('gcs/:filename', async ({ params, response }) => {
const filename = params.filename
const isDeleted = await Drive.disk('gcs').delete(filename)
response.send({ isDeleted: isDeleted })
})
Route.put('gcs/:filename/copy', async ({ params, request, response }) => {
const filename = params.filename
const dest = request.input('dest')
const isCopied = await Drive.disk('gcs').copy(filename, dest)
response.send({ isCopied: isCopied })
// if the file is publicly accessible, add options { public: true }
// const isCopied = await Drive.disk('gcs').copy(filename, dest, { public: true })
})
Route.put('gcs/:filename/move', async ({ params, request, response }) => {
const filename = params.filename
const dest = request.input('dest')
const destbucket = request.input('destbucket')
const isMoved = await Drive.disk('gcs').move(filename, dest, destbucket)
response.send({ isMoved: isMoved })
// if the file is publicly accessible, add options { public: true }
// const isMoved = await Drive.disk('gcs').move(filename, destname, destbucket, { public: true })
})