modernize backend to target the same ES and TS standards as the rest of the app
This commit is contained in:
parent
22f49db21f
commit
9beeca5942
29 changed files with 460 additions and 232 deletions
|
|
@ -287,7 +287,7 @@ export class MastodonConverters {
|
|||
this.getUser(p)
|
||||
.then(u => this.encode(u, mentionedRemoteUsers))
|
||||
.catch(() => null)))
|
||||
.then((p: Entity.Mention[]) => p.filter(m => m));
|
||||
.then((p: (Entity.Mention | null)[]) => p.filter(m => m != null));
|
||||
|
||||
const tags = note.tags.map(tag => {
|
||||
return {
|
||||
|
|
@ -345,7 +345,7 @@ export class MastodonConverters {
|
|||
sensitive: status.sensitive || !!cw,
|
||||
spoiler_text: cw,
|
||||
visibility: status.visibility,
|
||||
media_attachments: status.media_attachments.map((a: Entity.Account) => convertAttachment(a)),
|
||||
media_attachments: status.media_attachments.map((a: Entity.Attachment) => convertAttachment(a)),
|
||||
mentions: mentions,
|
||||
tags: tags,
|
||||
card: null, //FIXME
|
||||
|
|
|
|||
|
|
@ -41,8 +41,7 @@ export class ApiInstanceMastodon {
|
|||
const response: MastodonEntity.Instance = {
|
||||
uri: this.config.host,
|
||||
title: this.meta.name || 'Sharkey',
|
||||
shortDescription: this.meta.description || 'This is a vanilla Sharkey Instance. It doesn\'t seem to have a description.',
|
||||
description: this.meta.about || 'This is a vanilla Sharkey Instance.',
|
||||
description: this.meta.description || this.meta.about || 'This is a vanilla Sharkey Instance.',
|
||||
email: instance.email || '',
|
||||
version: `3.0.0 (compatible; Sharkey ${this.config.version}; like Akkoma)`,
|
||||
urls: instance.urls,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import { parseTimelineArgs, TimelineArgs, toBoolean, toInt } from '@/server/api/
|
|||
import { MastodonClientService } from '@/server/api/mastodon/MastodonClientService.js';
|
||||
import { MastodonDataService } from '@/server/api/mastodon/MastodonDataService.js';
|
||||
import { getNoteSummary } from '@/misc/get-note-summary.js';
|
||||
import type { Packed } from '@/misc/json-schema.js';
|
||||
import { isPureRenote } from '@/misc/is-renote.js';
|
||||
import { convertAttachment, convertPoll, MastodonConverters } from '../MastodonConverters.js';
|
||||
import type { Entity } from 'megalodon';
|
||||
|
|
@ -46,7 +45,34 @@ export class ApiStatusMastodon {
|
|||
|
||||
// Fixup - Discord ignores CWs and renders the entire post.
|
||||
if (response.sensitive && _request.headers['user-agent']?.match(/\bDiscordbot\//)) {
|
||||
response.content = getNoteSummary(data.data satisfies Packed<'Note'>);
|
||||
// TODO move this mastoConverters?
|
||||
response.content = getNoteSummary({
|
||||
...data.data,
|
||||
user: {
|
||||
...data.data.account,
|
||||
emojis: {},
|
||||
noindex: data.data.account.noindex ?? false,
|
||||
},
|
||||
visibility: data.data.visibility === 'direct'
|
||||
? 'specified'
|
||||
: data.data.visibility === 'private'
|
||||
? 'followers'
|
||||
: data.data.visibility === 'unlisted'
|
||||
? 'home'
|
||||
: data.data.visibility,
|
||||
mentions: data.data.mentions.map(m => m.id),
|
||||
tags: data.data.tags.map(t => t.name),
|
||||
poll: data.data.poll && {
|
||||
...data.data.poll,
|
||||
choices: data.data.poll.options.map(o => ({
|
||||
...o,
|
||||
text: o.title,
|
||||
votes: o.votes_count ?? 0,
|
||||
isVoted: o.votes_count != null,
|
||||
})),
|
||||
},
|
||||
emojis: {},
|
||||
});
|
||||
response.media_attachments = [];
|
||||
response.in_reply_to_id = null;
|
||||
response.in_reply_to_account_id = null;
|
||||
|
|
@ -182,7 +208,7 @@ export class ApiStatusMastodon {
|
|||
if (body.in_reply_to_id && removed === '/unreact') {
|
||||
const id = body.in_reply_to_id;
|
||||
const post = await client.getStatus(id);
|
||||
const react = post.data.emoji_reactions.filter((e: Entity.Emoji) => e.me)[0].name;
|
||||
const react = post.data.emoji_reactions.filter((e: Entity.Reaction) => e.me)[0].name;
|
||||
const data = await client.deleteEmojiReaction(id, react);
|
||||
return reply.send(data.data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
let forceError = localStorage.getItem('forceError');
|
||||
if (forceError != null) {
|
||||
renderError('FORCED_ERROR', 'This error is forced by having forceError in local storage.');
|
||||
renderError('FORCED_ERROR');
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ window.onload = async () => {
|
|||
|
||||
document.getElementById('submit').addEventListener('click', () => {
|
||||
api('notes/create', {
|
||||
text: document.getElementById('text').value
|
||||
text: (/** @type {HTMLInputElement} */(document.getElementById('text'))).value
|
||||
}).then(() => {
|
||||
location.reload();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
el.textContent = reload;
|
||||
}
|
||||
|
||||
/** @type {NodeListOf<HTMLElement>} */
|
||||
const i18nEls = document.querySelectorAll('[data-i18n]');
|
||||
for (const el of i18nEls) {
|
||||
const key = el.dataset.i18n;
|
||||
|
|
|
|||
3
packages/backend/src/server/web/global.d.ts
vendored
Normal file
3
packages/backend/src/server/web/global.d.ts
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
declare const CLIENT_ENTRY: string;
|
||||
declare const LANGS_VERSION: string;
|
||||
declare const LANGS: string[];
|
||||
Loading…
Add table
Add a link
Reference in a new issue