misskey post api

This commit is contained in:
Win 2024-07-08 21:36:36 +07:00
parent 552eba2e75
commit 1a2c418629
3 changed files with 36 additions and 7 deletions

4
.gitignore vendored
View File

@ -130,3 +130,7 @@ dist
.yarn/install-state.gz
.pnp.*
# custom config
config/*.json

View File

@ -0,0 +1,3 @@
{
"token": ""
}

View File

@ -53,23 +53,45 @@ async function get_access_token(host, session_id) {
});
const data = await response.json();
console.log(data);
const res_status = data.ok;
const res_token = data.token;
if(res_status) {
return res_token;
if(data.ok == true) {
return data.token;
} else {
return false; // error occured
}
};
(async () => {
let access_token = 0;
const token_file = JSON.parse(fs.readFileSync(path.resolve("config", "token.json")));
if(!token_file.token || token_file.token == "" || token_file.token == false) { // if existing token not exist
await check_auth_status()
let access_token = await get_access_token(host, session_id);
access_token = await get_access_token(host, session_id);
console.log(access_token);
let json_data = {
"token": access_token
}
fs.writeFileSync(
path.resolve("config", "token.json"),
JSON.stringify(json_data)
);
} else {
access_token = token_file.token;
}
const cli = new Misskey.api.APIClient({
origin: host,
credential: access_token
});
const meta = await cli.request('notes/create', {
text: "hi from misskey api!"
});
console.log(meta);
})();
app.listen(port);