mirror of
https://github.com/engineer-man/piston.git
synced 2025-05-02 01:46:28 +02:00
api: v3
This commit is contained in:
parent
d8239c2703
commit
91420c39d7
18 changed files with 2328 additions and 0 deletions
34
api/src/helpers.js
Normal file
34
api/src/helpers.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
const fs = require("fs"),
|
||||
path= require("path"),
|
||||
util = require("util"),
|
||||
fetch = require("node-fetch"),
|
||||
urlp = require("url")
|
||||
|
||||
|
||||
|
||||
module.exports = {
|
||||
async buffer_from_u_r_l(url){
|
||||
if(!(url instanceof URL))
|
||||
url = new URL(url)
|
||||
if(url.protocol == "file:"){
|
||||
//eslint-disable-next-line snakecasejs/snakecasejs
|
||||
return await util.promisify(fs.read_file)(urlp.fileURLToPath(url))
|
||||
}else{
|
||||
return await fetch({
|
||||
url: url.toString()
|
||||
})
|
||||
}
|
||||
},
|
||||
add_url_base_if_required(url, base){
|
||||
try{
|
||||
return new URL(url)
|
||||
}catch{
|
||||
//Assume this is a file name
|
||||
return new URL(url, base + "/")
|
||||
}
|
||||
},
|
||||
url_basename(url){
|
||||
return path.basename(url.pathname)
|
||||
},
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue