Skip to content

Commit

Permalink
upload file
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenilk committed Jun 3, 2023
1 parent f3d0439 commit d5cf89c
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,42 +46,42 @@ app.get("/getWant", async (req: Request, res: Response) => {
res.status(500).json({ message: error.message })
}
})
app.get("/version",async(req: Request, res: Response)=>{
await fs.readFile("appversion.txt",'utf-8',async(err:Error,data:any)=>{
let json =await JSON.stringify({"version":data})
res.json(json)
})
})
app.get("/updatePage", (req: Request, res: Response) => {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write('<form action="updateApp" method="post" enctype="multipart/form-data">');
res.write('<input type="text" name="version" placeholder="version"><br>');
res.write('<input type="file" name="filetoupload"><br>');
res.write('<input type="submit">');
res.write('</form>');
return res.end();
})
app.get("/downloadapp",async(req: Request, res: Response)=>{
res.download(path.join(__dirname+"/App/app-release.apk"))
})
app.post("/updateApp", (req: Request, res: Response) => {
var form = formidable({multiples:true})
console.log(form)
form.parse(req, function (err: Error, fields: any, files: any) {
var oldpath = files.filetoupload.filepath;
var version = fields["version"];
var newpath = path.join(__dirname + "/App/" + files.filetoupload.originalFilename);
fs.rename(oldpath, newpath, function (err: Error) {
if (err) throw err;
res.write('File uploaded and moved!');
res.end();
});
fs.writeFile('appversion.txt', String(version), function (err:Error) {
if (err) throw err;
console.log('Saved!');
});
})
})
// app.get("/version",async(req: Request, res: Response)=>{
// await fs.readFile("appversion.txt",'utf-8',async(err:Error,data:any)=>{
// let json =await JSON.stringify({"version":data})
// res.json(json)
// })
// })
// app.get("/updatePage", (req: Request, res: Response) => {
// res.writeHead(200, { 'Content-Type': 'text/html' });
// res.write('<form action="updateApp" method="post" enctype="multipart/form-data">');
// res.write('<input type="text" name="version" placeholder="version"><br>');
// res.write('<input type="file" name="filetoupload"><br>');
// res.write('<input type="submit">');
// res.write('</form>');
// return res.end();
// })
// app.get("/downloadapp",async(req: Request, res: Response)=>{
// res.download(path.join(__dirname+"/App/app-release.apk"))
// })
// app.post("/updateApp", (req: Request, res: Response) => {
// var form = formidable({multiples:true})
// console.log(form)
// form.parse(req, function (err: Error, fields: any, files: any) {
// var oldpath = files.filetoupload.filepath;
// var version = fields["version"];
// var newpath = path.join(__dirname + "/App/" + files.filetoupload.originalFilename);
// fs.rename(oldpath, newpath, function (err: Error) {
// if (err) throw err;
// res.write('File uploaded and moved!');
// res.end();
// });
// fs.writeFile('appversion.txt', String(version), function (err:Error) {
// if (err) throw err;
// console.log('Saved!');
// });
// })
// })
app.post("/postRf", async (req: Request, res: Response) => {
const data = InRefrigurator({
name: req.body.name,
Expand Down

2 comments on commit d5cf89c

@vercel
Copy link

@vercel vercel bot commented on d5cf89c Jun 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

refrigurator-api – ./

refrigurator-api-git-main-lenilk.vercel.app
refrigurator-api.vercel.app
refrigurator-api-lenilk.vercel.app

@vercel
Copy link

@vercel vercel bot commented on d5cf89c Jun 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.