[build] upgrade eslint to 9.37.0 (#88)

Co-authored-by: tobi <tobi.smethurst@protonmail.com>
Reviewed-on: https://codeberg.org/superseriousbusiness/masto-fe-standalone/pulls/88
Co-authored-by: Zoë Bijl <moiety@noreply.codeberg.org>
Co-committed-by: Zoë Bijl <moiety@noreply.codeberg.org>
This commit is contained in:
Zoë Bijl
2025-10-12 13:42:02 +02:00
committed by tobi
parent 75d7a62693
commit 1ff70886a1
975 changed files with 22196 additions and 21964 deletions
+19 -19
View File
@@ -1,18 +1,18 @@
import { ExpirationPlugin } from 'workbox-expiration';
import { precacheAndRoute } from 'workbox-precaching';
import { registerRoute } from 'workbox-routing';
import { CacheFirst } from 'workbox-strategies';
import { ExpirationPlugin } from "workbox-expiration";
import { precacheAndRoute } from "workbox-precaching";
import { registerRoute } from "workbox-routing";
import { CacheFirst } from "workbox-strategies";
import { handleNotificationClick, handlePush } from './web_push_notifications';
import { handleNotificationClick, handlePush } from "./web_push_notifications";
const CACHE_NAME_PREFIX = 'mastodon-';
const CACHE_NAME_PREFIX = "mastodon-";
function openWebCache() {
return caches.open(`${CACHE_NAME_PREFIX}web`);
}
function fetchRoot() {
return fetch('/', { credentials: 'include', redirect: 'manual' });
return fetch("/", { credentials: "include", redirect: "manual" });
}
precacheAndRoute(self.__WB_MANIFEST);
@@ -31,7 +31,7 @@ registerRoute(
);
registerRoute(
({ request }) => request.destination === 'font',
({ request }) => request.destination === "font",
new CacheFirst({
cacheName: `${CACHE_NAME_PREFIX}fonts`,
plugins: [
@@ -44,7 +44,7 @@ registerRoute(
);
registerRoute(
({ request }) => request.destination === 'image',
({ request }) => request.destination === "image",
new CacheFirst({
cacheName: `m${CACHE_NAME_PREFIX}media`,
plugins: [
@@ -58,26 +58,26 @@ registerRoute(
// Cause a new version of a registered Service Worker to replace an existing one
// that is already installed, and replace the currently active worker on open pages.
self.addEventListener('install', function(event) {
event.waitUntil(Promise.all([openWebCache(), fetchRoot()]).then(([cache, root]) => cache.put('/', root)));
self.addEventListener("install", function(event) {
event.waitUntil(Promise.all([openWebCache(), fetchRoot()]).then(([cache, root]) => cache.put("/", root)));
});
self.addEventListener('activate', function(event) {
self.addEventListener("activate", function(event) {
event.waitUntil(self.clients.claim());
});
self.addEventListener('fetch', function(event) {
self.addEventListener("fetch", function(event) {
const url = new URL(event.request.url);
if (url.pathname === '/auth/sign_out') {
if (url.pathname === "/auth/sign_out") {
const asyncResponse = fetch(event.request);
const asyncCache = openWebCache();
event.respondWith(asyncResponse.then(response => {
if (response.ok || response.type === 'opaqueredirect') {
if (response.ok || response.type === "opaqueredirect") {
return Promise.all([
asyncCache.then(cache => cache.delete('/')),
indexedDB.deleteDatabase('mastodon'),
asyncCache.then(cache => cache.delete("/")),
indexedDB.deleteDatabase("mastodon"),
]).then(() => response);
}
@@ -86,5 +86,5 @@ self.addEventListener('fetch', function(event) {
}
});
self.addEventListener('push', handlePush);
self.addEventListener('notificationclick', handleNotificationClick);
self.addEventListener("push", handlePush);
self.addEventListener("notificationclick", handleNotificationClick);
@@ -1,37 +1,38 @@
/* eslint-disable import/no-commonjs --
We need to use CommonJS here as its imported into a preval file (`emoji_compressed.js`) */
/* @preval */
const fs = require('fs');
const path = require('path');
const fs = require("fs");
const path = require("path");
const filtered = {};
const filenames = fs.readdirSync(path.resolve(__dirname, '../locales'));
const filenames = fs.readdirSync(path.resolve(__dirname, "../locales"));
filenames.forEach(filename => {
if (!filename.match(/\.json$/)) return;
if (!filename.match(/\.json$/)) {
return;
}
const content = fs.readFileSync(path.resolve(__dirname, `../locales/${filename}`), 'utf-8');
const content = fs.readFileSync(path.resolve(__dirname, `../locales/${filename}`), "utf-8");
const full = JSON.parse(content);
const locale = filename.split('.')[0];
const locale = filename.split(".")[0];
filtered[locale] = {
'notification.favourite': full['notification.favourite'] || '',
'notification.follow': full['notification.follow'] || '',
'notification.follow_request': full['notification.follow_request'] || '',
'notification.mention': full['notification.mention'] || '',
'notification.reblog': full['notification.reblog'] || '',
'notification.poll': full['notification.poll'] || '',
'notification.status': full['notification.status'] || '',
'notification.update': full['notification.update'] || '',
'notification.admin.sign_up': full['notification.admin.sign_up'] || '',
"notification.favourite": full["notification.favourite"] || "",
"notification.follow": full["notification.follow"] || "",
"notification.follow_request": full["notification.follow_request"] || "",
"notification.mention": full["notification.mention"] || "",
"notification.reblog": full["notification.reblog"] || "",
"notification.poll": full["notification.poll"] || "",
"notification.status": full["notification.status"] || "",
"notification.update": full["notification.update"] || "",
"notification.admin.sign_up": full["notification.admin.sign_up"] || "",
'status.show_more': full['status.show_more'] || '',
'status.reblog': full['status.reblog'] || '',
'status.favourite': full['status.favourite'] || '',
"status.show_more": full["status.show_more"] || "",
"status.reblog": full["status.reblog"] || "",
"status.favourite": full["status.favourite"] || "",
'notifications.group': full['notifications.group'] || '',
"notifications.group": full["notifications.group"] || "",
};
});
@@ -1,23 +1,23 @@
import { IntlMessageFormat } from 'intl-messageformat';
import { IntlMessageFormat } from "intl-messageformat";
import { unescape } from 'lodash';
import { unescape } from "lodash";
import locales from './web_push_locales';
import locales from "./web_push_locales";
const MAX_NOTIFICATIONS = 5;
const GROUP_TAG = 'tag';
const GROUP_TAG = "tag";
const notify = options =>
self.registration.getNotifications().then(notifications => {
if (notifications.length >= MAX_NOTIFICATIONS) { // Reached the maximum number of notifications, proceed with grouping
const group = {
title: formatMessage('notifications.group', options.data.preferred_locale, { count: notifications.length + 1 }),
body: notifications.sort((n1, n2) => n1.timestamp < n2.timestamp).map(notification => notification.title).join('\n'),
badge: '/badge.png',
icon: '/android-chrome-192x192.png',
title: formatMessage("notifications.group", options.data.preferred_locale, { count: notifications.length + 1 }),
body: notifications.sort((n1, n2) => n1.timestamp < n2.timestamp).map(notification => notification.title).join("\n"),
badge: "/badge.png",
icon: "/android-chrome-192x192.png",
tag: GROUP_TAG,
data: {
url: (new URL('/notifications', self.location)).href,
url: (new URL("/notifications", self.location)).href,
count: notifications.length + 1,
preferred_locale: options.data.preferred_locale,
},
@@ -29,7 +29,7 @@ const notify = options =>
} else if (notifications.length === 1 && notifications[0].tag === GROUP_TAG) { // Already grouped, proceed with appending the notification to the group
const group = cloneNotification(notifications[0]);
group.title = formatMessage('notifications.group', options.data.preferred_locale, { count: group.data.count + 1 });
group.title = formatMessage("notifications.group", options.data.preferred_locale, { count: group.data.count + 1 });
group.body = `${options.title}\n${group.body}`;
group.data = { ...group.data, count: group.data.count + 1 };
@@ -44,12 +44,12 @@ const fetchFromApi = (path, method, accessToken) => {
return fetch(url, {
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json',
"Authorization": `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
method: method,
credentials: 'include',
credentials: "include",
}).then(res => {
if (res.ok) {
return res;
@@ -75,14 +75,14 @@ const formatMessage = (messageId, locale, values = {}) =>
(new IntlMessageFormat(locales[locale][messageId], locale)).format(values);
const htmlToPlainText = html =>
unescape(html.replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n').replace(/<[^>]*>/g, ''));
unescape(html.replace(/<br\s*\/?>/g, "\n").replace(/<\/p><p>/g, "\n\n").replace(/<[^>]*>/g, ""));
export const handlePush = (event) => {
const { access_token, notification_id, preferred_locale, title, body, icon } = event.data.json();
// Placeholder until more information can be loaded
event.waitUntil(
fetchFromApi(`/api/v1/notifications/${notification_id}`, 'get', access_token).then(notification => {
fetchFromApi(`/api/v1/notifications/${notification_id}`, "get", access_token).then(notification => {
const options = {};
options.title = formatMessage(`notification.${notification.type}`, preferred_locale, { name: notification.account.display_name.length > 0 ? notification.account.display_name : notification.account.username });
@@ -90,7 +90,7 @@ export const handlePush = (event) => {
options.icon = notification.account.avatar_static;
options.timestamp = notification.created_at && new Date(notification.created_at);
options.tag = notification.id;
options.badge = '/badge.png';
options.badge = "/badge.png";
options.image = notification.status && notification.status.media_attachments.length > 0 && notification.status.media_attachments[0].preview_url || undefined;
options.data = { access_token, preferred_locale, id: notification.status ? notification.status.id : notification.account.id };
@@ -110,7 +110,7 @@ export const handlePush = (event) => {
options.image = undefined;
options.actions = [actionExpand(preferred_locale)];
} else if (['mention', 'status'].includes(notification.type)) {
} else if (["mention", "status"].includes(notification.type)) {
options.actions = [actionReblog(preferred_locale), actionFavourite(preferred_locale)];
}
@@ -122,34 +122,34 @@ export const handlePush = (event) => {
icon,
tag: notification_id,
timestamp: new Date(),
badge: '/badge.png',
data: { access_token, preferred_locale, url: '/notifications' },
badge: "/badge.png",
data: { access_token, preferred_locale, url: "/notifications" },
});
}),
);
};
const actionExpand = preferred_locale => ({
action: 'expand',
icon: '/web-push-icon_expand.png',
title: formatMessage('status.show_more', preferred_locale),
action: "expand",
icon: "/web-push-icon_expand.png",
title: formatMessage("status.show_more", preferred_locale),
});
const actionReblog = preferred_locale => ({
action: 'reblog',
icon: '/web-push-icon_reblog.png',
title: formatMessage('status.reblog', preferred_locale),
action: "reblog",
icon: "/web-push-icon_reblog.png",
title: formatMessage("status.reblog", preferred_locale),
});
const actionFavourite = preferred_locale => ({
action: 'favourite',
icon: '/web-push-icon_favourite.png',
title: formatMessage('status.favourite', preferred_locale),
action: "favourite",
icon: "/web-push-icon_favourite.png",
title: formatMessage("status.favourite", preferred_locale),
});
const findBestClient = clients => {
const focusedClient = clients.find(client => client.focused);
const visibleClient = clients.find(client => client.visibilityState === 'visible');
const visibleClient = clients.find(client => client.visibilityState === "visible");
return focusedClient || visibleClient || clients[0];
};
@@ -173,8 +173,8 @@ const removeActionFromNotification = (notification, action) => {
};
const openUrl = url =>
self.clients.matchAll({ type: 'window' }).then(clientList => {
if (clientList.length !== 0 && 'navigate' in clientList[0]) { // Chrome 42-48 does not support navigate
self.clients.matchAll({ type: "window" }).then(clientList => {
if (clientList.length !== 0 && "navigate" in clientList[0]) { // Chrome 42-48 does not support navigate
const client = findBestClient(clientList);
return client.navigate(url).then(client => client.focus());
@@ -186,14 +186,14 @@ const openUrl = url =>
export const handleNotificationClick = (event) => {
const reactToNotificationClick = new Promise((resolve, reject) => {
if (event.action) {
if (event.action === 'expand') {
if (event.action === "expand") {
resolve(expandNotification(event.notification));
} else if (event.action === 'reblog') {
} else if (event.action === "reblog") {
const { data } = event.notification;
resolve(fetchFromApi(`/api/v1/statuses/${data.id}/reblog`, 'post', data.access_token).then(() => removeActionFromNotification(event.notification, 'reblog')));
} else if (event.action === 'favourite') {
resolve(fetchFromApi(`/api/v1/statuses/${data.id}/reblog`, "post", data.access_token).then(() => removeActionFromNotification(event.notification, "reblog")));
} else if (event.action === "favourite") {
const { data } = event.notification;
resolve(fetchFromApi(`/api/v1/statuses/${data.id}/favourite`, 'post', data.access_token).then(() => removeActionFromNotification(event.notification, 'favourite')));
resolve(fetchFromApi(`/api/v1/statuses/${data.id}/favourite`, "post", data.access_token).then(() => removeActionFromNotification(event.notification, "favourite")));
} else {
reject(`Unknown action: ${event.action}`);
}