mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-10 21:10:54 +01:00
Run prettier
This commit is contained in:
parent
8a8bf14a16
commit
54507d077c
5 changed files with 46 additions and 29 deletions
|
@ -10,7 +10,7 @@ import { renderInstantView } from '../render/instantview';
|
||||||
import { constructTwitterThread } from '../providers/twitter/conversation';
|
import { constructTwitterThread } from '../providers/twitter/conversation';
|
||||||
import { Experiment, experimentCheck } from '../experiments';
|
import { Experiment, experimentCheck } from '../experiments';
|
||||||
import i18next from 'i18next';
|
import i18next from 'i18next';
|
||||||
import icu from "i18next-icu";
|
import icu from 'i18next-icu';
|
||||||
import translationResources from '../../i18n/resources.json';
|
import translationResources from '../../i18n/resources.json';
|
||||||
|
|
||||||
export const returnError = (c: Context, error: string): Response => {
|
export const returnError = (c: Context, error: string): Response => {
|
||||||
|
@ -488,7 +488,7 @@ export const handleStatus = async (
|
||||||
const mediaType = overrideMedia ?? status.media.videos?.[0]?.type;
|
const mediaType = overrideMedia ?? status.media.videos?.[0]?.type;
|
||||||
|
|
||||||
if (mediaType === 'gif') {
|
if (mediaType === 'gif') {
|
||||||
provider = i18next.t('gifIndicator', {brandingName: Constants.BRANDING_NAME});
|
provider = i18next.t('gifIndicator', { brandingName: Constants.BRANDING_NAME });
|
||||||
} else if (
|
} else if (
|
||||||
status.embed_card === 'player' &&
|
status.embed_card === 'player' &&
|
||||||
providerEngagementText !== Strings.DEFAULT_AUTHOR_TEXT
|
providerEngagementText !== Strings.DEFAULT_AUTHOR_TEXT
|
||||||
|
|
|
@ -115,8 +115,8 @@ const notApplicableComment = '<!-- N/A -->';
|
||||||
|
|
||||||
const truncateSocialCount = (count: number, locale = 'en-US') => {
|
const truncateSocialCount = (count: number, locale = 'en-US') => {
|
||||||
const formatter = new Intl.NumberFormat(locale, {
|
const formatter = new Intl.NumberFormat(locale, {
|
||||||
notation: "compact",
|
notation: 'compact',
|
||||||
compactDisplay: "short",
|
compactDisplay: 'short',
|
||||||
maximumFractionDigits: 1
|
maximumFractionDigits: 1
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -170,7 +170,12 @@ const wrapForeignLinks = (url: string) => {
|
||||||
: url;
|
: url;
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateStatusFooter = (status: APIStatus, isQuote = false, author: APIUser, language: string): string => {
|
const generateStatusFooter = (
|
||||||
|
status: APIStatus,
|
||||||
|
isQuote = false,
|
||||||
|
author: APIUser,
|
||||||
|
language: string
|
||||||
|
): string => {
|
||||||
let description = author.description;
|
let description = author.description;
|
||||||
description = htmlifyLinks(description);
|
description = htmlifyLinks(description);
|
||||||
description = htmlifyHashtags(description);
|
description = htmlifyHashtags(description);
|
||||||
|
@ -221,10 +226,10 @@ const generatePoll = (poll: APIPoll, language: string): string => {
|
||||||
poll.choices.forEach(choice => {
|
poll.choices.forEach(choice => {
|
||||||
const bar = '█'.repeat((choice.percentage / 100) * barLength);
|
const bar = '█'.repeat((choice.percentage / 100) * barLength);
|
||||||
// eslint-disable-next-line no-irregular-whitespace
|
// eslint-disable-next-line no-irregular-whitespace
|
||||||
str += `${bar}<br>${choice.label}<br>${i18next.t('ivPollChoice', { voteCount: intlFormat.format(choice.count), percentage: intlFormat.format(choice.percentage)})}<br>`;
|
str += `${bar}<br>${choice.label}<br>${i18next.t('ivPollChoice', { voteCount: intlFormat.format(choice.count), percentage: intlFormat.format(choice.percentage) })}<br>`;
|
||||||
});
|
});
|
||||||
/* Finally, add the footer of the poll with # of votes and time left */
|
/* Finally, add the footer of the poll with # of votes and time left */
|
||||||
str += `<br>${i18next.t('pollVotes', { voteCount: intlFormat.format(poll.total_votes), timeLeft: poll.time_left_en})}`;
|
str += `<br>${i18next.t('pollVotes', { voteCount: intlFormat.format(poll.total_votes), timeLeft: poll.time_left_en })}`;
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
@ -300,8 +305,8 @@ const generateStatus = (
|
||||||
<!-- Embed poll -->
|
<!-- Embed poll -->
|
||||||
${status.poll ? generatePoll(status.poll, status.lang ?? 'en') : notApplicableComment}
|
${status.poll ? generatePoll(status.poll, status.lang ?? 'en') : notApplicableComment}
|
||||||
<!-- Embedded quote status -->
|
<!-- Embedded quote status -->
|
||||||
${!isQuote && status.quote ? generateStatus(status.quote, author, language, true, null) : notApplicableComment}`
|
${!isQuote && status.quote ? generateStatus(status.quote, author, language, true, null) : notApplicableComment}`.format(
|
||||||
.format({
|
{
|
||||||
quoteHeader: isQuote
|
quoteHeader: isQuote
|
||||||
? '<h4>' +
|
? '<h4>' +
|
||||||
i18next.t('ivQuoteHeader').format({
|
i18next.t('ivQuoteHeader').format({
|
||||||
|
@ -312,7 +317,8 @@ const generateStatus = (
|
||||||
}) +
|
}) +
|
||||||
'</h4>'
|
'</h4>'
|
||||||
: ''
|
: ''
|
||||||
});
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const renderInstantView = (properties: RenderProperties): ResponseInstructions => {
|
export const renderInstantView = (properties: RenderProperties): ResponseInstructions => {
|
||||||
|
@ -323,7 +329,7 @@ export const renderInstantView = (properties: RenderProperties): ResponseInstruc
|
||||||
let previousThreadPieceAuthor: string | null = null;
|
let previousThreadPieceAuthor: string | null = null;
|
||||||
let originalAuthor: string | null = null;
|
let originalAuthor: string | null = null;
|
||||||
|
|
||||||
const useThread = thread?.thread ?? [ thread?.status ]
|
const useThread = thread?.thread ?? [thread?.status];
|
||||||
|
|
||||||
if (!status) {
|
if (!status) {
|
||||||
throw new Error('Status is undefined');
|
throw new Error('Status is undefined');
|
||||||
|
@ -359,7 +365,8 @@ export const renderInstantView = (properties: RenderProperties): ResponseInstruc
|
||||||
<sub><a href="${status.url}">${i18next.t('ivViewOriginal')}</a></sub>
|
<sub><a href="${status.url}">${i18next.t('ivViewOriginal')}</a></sub>
|
||||||
<h1>${status.author.name} (@${status.author.screen_name})</h1>
|
<h1>${status.author.name} (@${status.author.screen_name})</h1>
|
||||||
|
|
||||||
${useThread.map(status => {
|
${useThread
|
||||||
|
.map(status => {
|
||||||
console.log('previousThreadPieceAuthor', previousThreadPieceAuthor);
|
console.log('previousThreadPieceAuthor', previousThreadPieceAuthor);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
return '';
|
return '';
|
||||||
|
@ -395,7 +402,13 @@ export const renderInstantView = (properties: RenderProperties): ResponseInstruc
|
||||||
|
|
||||||
previousThreadPieceAuthor = status.author?.id;
|
previousThreadPieceAuthor = status.author?.id;
|
||||||
|
|
||||||
return generateStatus(status, status.author ?? thread?.author, properties?.targetLanguage ?? 'en', false, authorAction,);
|
return generateStatus(
|
||||||
|
status,
|
||||||
|
status.author ?? thread?.author,
|
||||||
|
properties?.targetLanguage ?? 'en',
|
||||||
|
false,
|
||||||
|
authorAction
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.join('')}
|
.join('')}
|
||||||
${generateStatusFooter(status, false, thread?.author ?? status.author, properties?.targetLanguage ?? 'en')}
|
${generateStatusFooter(status, false, thread?.author ?? status.author, properties?.targetLanguage ?? 'en')}
|
||||||
|
|
|
@ -14,7 +14,9 @@ export const renderPhoto = (
|
||||||
|
|
||||||
const all = status.media?.all as APIMedia[];
|
const all = status.media?.all as APIMedia[];
|
||||||
const baseString =
|
const baseString =
|
||||||
all.length === status.media?.photos?.length ? i18next.t('photoCount') : i18next.t('mediaCount');
|
all.length === status.media?.photos?.length
|
||||||
|
? i18next.t('photoCount')
|
||||||
|
: i18next.t('mediaCount');
|
||||||
|
|
||||||
const photoCounter = baseString.format({
|
const photoCounter = baseString.format({
|
||||||
number: String(all.indexOf(photo) + 1),
|
number: String(all.indexOf(photo) + 1),
|
||||||
|
|
|
@ -33,7 +33,9 @@ export const renderVideo = (
|
||||||
we'll put an indicator if there are more than one video */
|
we'll put an indicator if there are more than one video */
|
||||||
if (all && all.length > 1 && (userAgent?.indexOf('Telegram') ?? 0) > -1) {
|
if (all && all.length > 1 && (userAgent?.indexOf('Telegram') ?? 0) > -1) {
|
||||||
const baseString =
|
const baseString =
|
||||||
all.length === status.media?.videos?.length ? i18next.t('videoCount') : i18next.t('mediaCount');
|
all.length === status.media?.videos?.length
|
||||||
|
? i18next.t('videoCount')
|
||||||
|
: i18next.t('mediaCount');
|
||||||
const videoCounter = baseString.format({
|
const videoCounter = baseString.format({
|
||||||
number: String(all.indexOf(video) + 1),
|
number: String(all.indexOf(video) + 1),
|
||||||
total: String(all.length)
|
total: String(all.length)
|
||||||
|
|
Loading…
Add table
Reference in a new issue