Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kakkokari-gtyih committed Sep 9, 2024
1 parent 2ea0b57 commit 21e23c0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/frontend-shared/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import pluginVue from 'eslint-plugin-vue';
import pluginMisskey from '@misskey-dev/eslint-plugin';
import sharedConfig from '../shared/eslint.config.js';

// eslint-disable-next-line import/no-default-export
export default [
...sharedConfig,
{
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend-shared/js/embed-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function parseEmbedParams(searchParams: URLSearchParams | string): Parsed
}

function convertColorMode(value: string | null): 'light' | 'dark' | undefined {
if (value != null && [ 'light', 'dark' ].includes(value)) {
if (value != null && ['light', 'dark'].includes(value)) {
return value as 'light' | 'dark';
}
return undefined;
Expand Down
1 change: 1 addition & 0 deletions packages/frontend-shared/js/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
import type { ILocale, ParameterizedString } from '../../../locales/index.js';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type TODO = any;

type FlattenKeys<T extends ILocale, TPrediction> = keyof {
Expand Down
7 changes: 4 additions & 3 deletions packages/frontend-shared/js/media-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/

import { query } from './url.js';
import * as Misskey from 'misskey-js';
import { query } from './url.js';

export class MediaProxy {
private serverMetadata: Misskey.entities.MetaDetailed;
Expand All @@ -17,17 +17,18 @@ export class MediaProxy {

public getProxiedImageUrl(imageUrl: string, type?: 'preview' | 'emoji' | 'avatar', mustOrigin = false, noFallback = false): string {
const localProxy = `${this.url}/proxy`;
let _imageUrl = imageUrl;

if (imageUrl.startsWith(this.serverMetadata.mediaProxy + '/') || imageUrl.startsWith('/proxy/') || imageUrl.startsWith(localProxy + '/')) {
// もう既にproxyっぽそうだったらurlを取り出す
imageUrl = (new URL(imageUrl)).searchParams.get('url') ?? imageUrl;
_imageUrl = (new URL(imageUrl)).searchParams.get('url') ?? imageUrl;
}

return `${mustOrigin ? localProxy : this.serverMetadata.mediaProxy}/${
type === 'preview' ? 'preview.webp'
: 'image.webp'
}?${query({
url: imageUrl,
url: _imageUrl,
...(!noFallback ? { 'fallback': '1' } : {}),
...(type ? { [type]: '1' } : {}),
...(mustOrigin ? { origin: '1' } : {}),
Expand Down
10 changes: 5 additions & 5 deletions packages/frontend-shared/js/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
* 2. プロパティがundefinedの時はクエリを付けない
* (new URLSearchParams(obj)ではそこまで丁寧なことをしてくれない)
*/
export function query(obj: Record<string, any>): string {
export function query(obj: Record<string, string | number | boolean>): string {
const params = Object.entries(obj)
.filter(([, v]) => Array.isArray(v) ? v.length : v !== undefined)
.reduce((a, [k, v]) => (a[k] = v, a), {} as Record<string, any>);
.filter(([, v]) => Array.isArray(v) ? v.length : v !== undefined) // eslint-disable-line @typescript-eslint/no-unnecessary-condition
.reduce<Record<string, string | number | boolean>>((a, [k, v]) => (a[k] = v, a), {});

return Object.entries(params)
.map((p) => `${p[0]}=${encodeURIComponent(p[1])}`)
.join('&');
}

export function appendQuery(url: string, query: string): string {
return `${url}${/\?/.test(url) ? url.endsWith('?') ? '' : '&' : '?'}${query}`;
export function appendQuery(url: string, queryString: string): string {
return `${url}${/\?/.test(url) ? url.endsWith('?') ? '' : '&' : '?'}${queryString}`;
}

export function extractDomain(url: string) {
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend-shared/js/use-document-visibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/

import { onMounted, onUnmounted, ref, Ref } from 'vue';
import { onMounted, onUnmounted, ref } from 'vue';
import type { Ref } from 'vue';

export function useDocumentVisibility(): Ref<DocumentVisibilityState> {
const visibility = ref(document.visibilityState);
Expand Down

0 comments on commit 21e23c0

Please sign in to comment.