Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import { Base64 } from 'https://deno.land/x/bb64/mod.ts'
export function saveFile(base64String, userId) {
const [ metadata, base64Image ] = base64String.split(';base64,')
// console.log(metadata)
const extension = metadata.split('/').pop()
const filename = `${userId}-${Date.now()}.${extension}`
const filePath = `/uploads/${filename}`
Base64.fromBase64String(base64Image).toFile(`./public${filePath}`)
return filePath
}
export function parseQueryString(search) {
const params = {}
search.slice(1).split('&').map(item=>{
const [ key, value ] = item.split('=')
return {
key,
value
}
}).forEach(({ key, value }) => {
params[key] = value
})
return params
}
export const transformCommodity = ({onSaleTime, ...rest}) => {
const date = new Date(onSaleTime)
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
return {...rest, onSaleTime: `${year}-${month}-${day}`}
}