cleaned up auth
This commit is contained in:
parent
d2a7b41a81
commit
e6a2ba6861
|
@ -1,4 +1,3 @@
|
|||
const express = require('express');
|
||||
const axios = require('axios');
|
||||
let auth_status = 0;
|
||||
|
||||
|
@ -23,17 +22,18 @@ function verify_auth_status() {
|
|||
}
|
||||
|
||||
async function get_access_token(host, session_id) {
|
||||
axios.post(`${host}/api/miauth/${session_id}/check`)
|
||||
.then((data) => {
|
||||
const response = data.json();
|
||||
|
||||
if(response.ok == true) {
|
||||
console.log(response.token);
|
||||
return response.token;
|
||||
} else {
|
||||
return false;
|
||||
const response = await axios.post(`${host}/api/miauth/${session_id}/check`, null, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
if(response.data.ok == true) {
|
||||
console.log("Successfully retrieved access token");
|
||||
return response.data.token;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.check_auth_status = check_auth_status;
|
||||
|
|
|
@ -1,16 +1,31 @@
|
|||
const axios = require('axios');
|
||||
const fs = require('fs');
|
||||
|
||||
async function create_image(host, access_token, file_path) {
|
||||
axios.post(`${host}/api/drive/files/create`, {
|
||||
const create = axios.post(`${host}/api/drive/files/create`, {
|
||||
file: fs.createReadStream(file_path)
|
||||
}, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
'Authorization': `Bearer ${access_token}`
|
||||
}
|
||||
}).then((data) => {
|
||||
return data;
|
||||
});
|
||||
|
||||
return create;
|
||||
};
|
||||
|
||||
async function create_note(host, access_token, text, media_ids, visibility) {
|
||||
axios.post(`${host}/api/notes/create`, {
|
||||
text: text,
|
||||
mediaIds: media_ids,
|
||||
visibility: visibility
|
||||
}, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${access_token}`
|
||||
}
|
||||
}).then((data) => {
|
||||
return data.json();
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.create_image = create_image;
|
13
src/index.js
13
src/index.js
|
@ -1,17 +1,15 @@
|
|||
import { v4 as uuidv4 } from 'uuid';
|
||||
import fs, { createReadStream } from 'node:fs';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import express from 'express';
|
||||
import axios from 'axios';
|
||||
import { fileFromPath } from 'formdata-node/file-from-path';
|
||||
import * as Misskey from 'misskey-js';
|
||||
|
||||
import * as Post from './api/post.cjs';
|
||||
import * as Auth from './api/auth.cjs';
|
||||
|
||||
const __dirname = path.resolve();
|
||||
const config = JSON.parse(fs.readFileSync(path.resolve("config", "config.json")));
|
||||
const token_file = JSON.parse(fs.readFileSync(path.resolve("config", "token.json")));
|
||||
const config = JSON.parse(fs.readFileSync(path.join(__dirname, '/config/config.json')));
|
||||
const token_file = JSON.parse(fs.readFileSync(path.join(__dirname, '/config/token.json')));
|
||||
|
||||
let app = express();
|
||||
let port = process.env.PORT || 4000;
|
||||
|
@ -60,7 +58,10 @@ app.get('/callback', function(req, res) {
|
|||
});
|
||||
|
||||
let static_image_path = path.join(__dirname, '/data/current_radar.jpg');
|
||||
Post.create_image(host, access_token, static_image_path);
|
||||
const upload_image = await Post.create_image(host, access_token, static_image_path);
|
||||
|
||||
console.log(upload_image);
|
||||
|
||||
})();
|
||||
|
||||
app.listen(port);
|
||||
|
|
Loading…
Reference in New Issue