misskey post api
This commit is contained in:
parent
552eba2e75
commit
1a2c418629
|
@ -130,3 +130,7 @@ dist
|
|||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
# custom config
|
||||
config/*.json
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"token": ""
|
||||
}
|
34
src/index.js
34
src/index.js
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue