refactor(all): prefer token-based authentication

This commit is contained in:
vulet 2021-01-17 17:58:02 +08:00
parent 9e17440abc
commit f69b52261a
24 changed files with 166 additions and 117 deletions

View file

@ -4,7 +4,7 @@ exports.runQuery = function (matrixClient, room, registrar) {
axios({
method: 'POST',
url: `${registrar.config.fediverse.domain}/api/v1/statuses`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
data: { status: `@10grans@fedi.cc beg` },
}).then((response) => {
matrixClient.sendHtmlNotice(room.roomId,
@ -18,4 +18,4 @@ exports.runQuery = function (matrixClient, room, registrar) {
matrixClient.sendHtmlNotice(room.roomId,
'', `${e}`);
});
};
};

View file

@ -4,7 +4,7 @@ exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({
method: 'POST',
url: `${registrar.config.fediverse.domain}/api/v1/statuses/${userInput}/unfavourite`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
}).then((response) => {
matrixClient.sendHtmlNotice(room.roomId,
'',

View file

@ -4,7 +4,7 @@ exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({
method: 'POST',
url: `${registrar.config.fediverse.domain}/api/v1/statuses/${userInput}/favourite`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
}).then((response) => {
matrixClient.sendHtmlNotice(room.roomId,
'',

View file

@ -4,7 +4,7 @@ exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({
method: 'POST',
url: `${registrar.config.fediverse.domain}/api/v1/statuses/${userInput}/reblog`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
}).then((response) => {
matrixClient.sendHtmlNotice(room.roomId,
'',

View file

@ -6,7 +6,7 @@ exports.runQuery = function (matrixClient, room, registrar) {
axios({
method: 'GET',
url: `${registrar.config.fediverse.domain}/api/v1/timelines/home`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
}).then((events) => {
const event = fs.readFileSync('timeline.json', 'utf8');
fs.writeFileSync('timeline.json', events.data[0].created_at, 'utf8');

View file

@ -5,7 +5,7 @@ exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({
method: 'POST',
url: `${registrar.config.fediverse.domain}/api/v1/accounts/${findUID.data.id}/follow`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
})
.then((response) => {
matrixClient.sendHtmlNotice(room.roomId,

View file

@ -26,7 +26,7 @@ const mediaDownload = async (url, { whitelist, blacklist }) => {
};
};
const mediaUpload = async ({ domain, token }, { data, filename, mimetype }) => {
const mediaUpload = async ({ domain }, { data, filename, mimetype }, registrar) => {
const form = new FormData();
form.append('file', data, {
filename: filename || 'upload',
@ -35,7 +35,7 @@ const mediaUpload = async ({ domain, token }, { data, filename, mimetype }) => {
const upload = await axios({
method: 'POST',
url: `${domain}/api/v1/media`,
headers: form.getHeaders({ Authorization: `Bearer ${token}` }),
headers: form.getHeaders({ Authorization: `Bearer ${registrar.fediverse_auth.access_token}` }),
data: form,
});
if(upload.statusText !== 'OK') throw upload;
@ -47,12 +47,12 @@ const run = async (matrixClient, { roomId }, content, replyId, mediaURL, subject
const fediverse = registrar.config.fediverse;
if(mediaURL) {
const media = await mediaDownload(mediaURL, registrar.config.fediverse.mimetypes);
mediaId = await mediaUpload(fediverse, media);
mediaId = await mediaUpload(fediverse, media, registrar);
}
const response = await axios({
method: 'POST',
url: `${fediverse.domain}/api/v1/statuses`,
headers: { Authorization: `Bearer ${fediverse.token}`, 'Content-Type': 'application/x-www-form-urlencoded' },
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}`, 'Content-Type': 'application/x-www-form-urlencoded' },
data : qs.stringify({
status: content,
content_type: `text/markdown`,

View file

@ -4,9 +4,9 @@ exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({
method: 'POST',
url: `${registrar.config.fediverse.domain}/api/v1/statuses`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
data: {
status: `@mordekai ${userInput}`,
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
data: {
status: `@mordekai ${userInput}`,
content_type: `text/markdown`,
visibility: 'unlisted',
expires_in: '7200'

View file

@ -6,7 +6,7 @@ exports.runQuery = function (matrixClient, room, registrar) {
axios({
method: 'GET',
url: `${registrar.config.fediverse.domain}/api/v1/notifications`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
}).then((notifications) => {
const event = fs.readFileSync('notification.json', 'utf8');
fs.writeFileSync('notification.json', notifications.data[0].created_at, 'utf8');

View file

@ -4,7 +4,7 @@ exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({
method: 'POST',
url: `${registrar.config.fediverse.domain}/api/v1/statuses/${userInput}/pin`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
}).then((response) => {
matrixClient.sendHtmlNotice(room.roomId,
'',

View file

@ -4,7 +4,7 @@ exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({
method: 'POST',
url: `${registrar.config.fediverse.domain}/api/v1/statuses`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
data: { status: userInput, content_type: `text/markdown` },
}).then((response) => {
matrixClient.sendHtmlNotice(room.roomId,

View file

@ -4,7 +4,7 @@ exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({
method: 'DELETE',
url: `${registrar.config.fediverse.domain}/api/v1/statuses/${userInput}`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
}).then((response) => {
matrixClient.sendHtmlNotice(room.roomId,
'',

View file

@ -4,7 +4,7 @@ exports.runQuery = function (matrixClient, room, address, flaggedInput, registra
axios({
method: 'POST',
url: `${registrar.config.fediverse.domain}/api/v1/statuses`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
data: { status: flaggedInput, in_reply_to_id: address, content_type: `text/markdown` },
}).then((response) => {
matrixClient.sendHtmlNotice(room.roomId,

View file

@ -4,7 +4,7 @@ exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({
method: 'GET',
url: `${registrar.config.fediverse.domain}/api/v1/statuses/${userInput}`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
}).then((response) => {
matrixClient.sendHtmlNotice(room.roomId,
'',

View file

@ -4,7 +4,7 @@ exports.runQuery = function (matrixClient, room, address, flaggedInput, registra
axios({
method: 'POST',
url: `${registrar.config.fediverse.domain}/api/v1/statuses`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
data: { status: `@10grans@fedi.cc tip `+ flaggedInput + ` to `+address },
}).then((response) => {
matrixClient.sendHtmlNotice(room.roomId,
@ -18,4 +18,4 @@ exports.runQuery = function (matrixClient, room, address, flaggedInput, registra
matrixClient.sendHtmlNotice(room.roomId,
'', `${e}`);
});
};
};

View file

@ -5,7 +5,7 @@ exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({
method: 'POST',
url: `${registrar.config.fediverse.domain}/api/v1/accounts/${findUID.data.id}/unfollow`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
})
.then((response) => {
matrixClient.sendHtmlNotice(room.roomId,

View file

@ -4,7 +4,7 @@ exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({
method: 'POST',
url: `${registrar.config.fediverse.domain}/api/v1/statuses/${userInput}/unpin`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
}).then((response) => {
matrixClient.sendHtmlNotice(room.roomId,
'',