Made file reading sync

This commit is contained in:
2021-01-19 12:57:14 +03:00
parent ef94f64d21
commit 1aa0c31535

View File

@@ -1,6 +1,7 @@
import Express from "express"; import Express from "express";
import Cors from "cors"; import Cors from "cors";
import path from "path"; import path from "path";
import fs from "fs";
const __dirname = path.resolve(); const __dirname = path.resolve();
import dotenv from 'dotenv'; import dotenv from 'dotenv';
@@ -17,17 +18,12 @@ app.use(Cors());
app.get('/update', (req, res) => { app.get('/update', (req, res) => {
var id = statusIds[Math.floor(Math.random() * statusIds.length)]; var id = statusIds[Math.floor(Math.random() * statusIds.length)];
let token; let token = fs.readFileSync('../../get-vk-token/token.txt', 'utf8');
fs.readFile('../get-vk-token/token.txt', 'utf8', function(error, data) { console.log(token);
if (error) {
console.log(error);
}
token = data;
});
let url = `https://api.vk.com/method/status.setImage?access_token=${token}&status_id=${id}&v=5.103`; let url = `https://api.vk.com/method/status.setImage?access_token=${token}&status_id=${id}&v=5.103`;
httpsReq(url).then((response) => { httpsReq(url).then((response) => {
console.log(response); console.log(response);
//res.redirect("https://status.anatolykopyl.ru"); res.redirect("https://status.anatolykopyl.ru");
res.send(); res.send();
}); });
}); });