Skip to content

Commit

Permalink
Merge pull request #4 from hey-api/chore/db-write
Browse files Browse the repository at this point in the history
chore: write to database
  • Loading branch information
mrlubos authored Apr 13, 2024
2 parents 5966bb2 + c4cbf16 commit 9f5a81d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
24 changes: 18 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

29 changes: 23 additions & 6 deletions src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,35 @@ export async function upload(pathToOpenApi: string): Promise<void> {
}

const fileBody = readFileSync(pathToOpenApi)
const parts = pathToOpenApi.split('/')

const match = pathToOpenApi.match(/\.[0-9a-z]+$/i)
const extension = match ? match[0] : ''

// TODO: replace with unique bucket name
const name = `@hey-api/upload-openapi-spec/${new Date().toISOString()}`
const { error } = await supabase.storage
const fileName = new Date().toISOString() + extension
const org = '@hey-api'
const project = 'upload-openapi-spec'
const filePath = `${org}/${project}/${fileName}`

const uploadResponse = await supabase.storage
.from('openapi-specs')
.upload(name, fileBody, {
.upload(filePath, fileBody, {
cacheControl: '3600',
upsert: false
})

if (error) {
throw new Error(error.message)
if (uploadResponse.error) {
throw new Error(uploadResponse.error.message)
}

const insertResponse = await supabase.from('openapi-specs').insert({
org,
path: filePath,
project
})

if (insertResponse.error) {
throw new Error(insertResponse.error.message)
}

resolve()
Expand Down

0 comments on commit 9f5a81d

Please sign in to comment.