@@ -6,6 +6,8 @@ const NetlifyAPI = require('netlify')
6
6
const client = new NetlifyAPI ( process . env . NETLIFY_API_TOKEN )
7
7
const site_id = 'b8d481fc-f70c-45f8-9242-3936c27fe7e6'
8
8
9
+ const fetch = require ( 'node-fetch' )
10
+
9
11
const uploadFile = async ( { deployId, path, buffer } ) => {
10
12
const bufferStream = new stream . PassThrough ( )
11
13
bufferStream . end ( buffer )
@@ -19,6 +21,23 @@ const uploadFile = async ({ deployId, path, buffer }) => {
19
21
return result
20
22
}
21
23
24
+ const directUploadFile = async ( { deployId, path, buffer } ) => {
25
+
26
+ const uri = `https://api.netlify.com/api/v1/deploys/${ deployId } /files/${ path } `
27
+
28
+ const options = {
29
+ method : 'PUT' ,
30
+ headers : {
31
+ 'Authorization' : `Bearer ${ process . env . NETLIFY_API_TOKEN } ` ,
32
+ 'Content-Type' : 'application/octet-stream'
33
+ } ,
34
+ body : buffer
35
+ }
36
+
37
+ const result = await fetch ( uri , options )
38
+ return await result . json ( )
39
+ }
40
+
22
41
const upload = async ( ) => {
23
42
let files = [ ]
24
43
try {
@@ -73,19 +92,20 @@ const upload = async () => {
73
92
//console.log(uploadList)
74
93
75
94
result = await Promise . all (
76
- uploadList . map ( item => uploadFile ( item ) )
95
+ //uploadList.map(item => uploadFile(item))
96
+ uploadList . map ( item => directUploadFile ( item ) )
77
97
)
78
- console . log ( 'Why are all fields capitalized?' )
98
+ console . log ( 'Why are all fields capitalized, even without the js-client ?' )
79
99
console . log ( result )
80
100
81
- console . log ( '.. but other endpoints are *NOT* capitalized?' )
82
- let site
83
- try {
84
- site = await client . getSite ( { site_id } )
85
- } catch ( e ) {
86
- console . log ( e . json )
87
- }
88
- console . log ( site )
101
+ // console.log('.. but other endpoints are *NOT* capitalized?')
102
+ // let site
103
+ // try {
104
+ // site = await client.getSite({ site_id })
105
+ // } catch (e) {
106
+ // console.log(e.json)
107
+ // }
108
+ // console.log(site)
89
109
90
110
}
91
111
0 commit comments