chore: migrate to oxlint and oxfmt

Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
Peter Steinberger
2026-01-14 14:31:43 +00:00
parent 912ebffc63
commit c379191f80
1480 changed files with 28608 additions and 43547 deletions

View File

@@ -22,37 +22,21 @@ type DownloadCandidate = {
placeholder: string;
};
function resolveDownloadCandidate(
att: MSTeamsAttachmentLike,
): DownloadCandidate | null {
function resolveDownloadCandidate(att: MSTeamsAttachmentLike): DownloadCandidate | null {
const contentType = normalizeContentType(att.contentType);
const name = typeof att.name === "string" ? att.name.trim() : "";
if (contentType === "application/vnd.microsoft.teams.file.download.info") {
if (!isRecord(att.content)) return null;
const downloadUrl =
typeof att.content.downloadUrl === "string"
? att.content.downloadUrl.trim()
: "";
typeof att.content.downloadUrl === "string" ? att.content.downloadUrl.trim() : "";
if (!downloadUrl) return null;
const fileType =
typeof att.content.fileType === "string"
? att.content.fileType.trim()
: "";
const uniqueId =
typeof att.content.uniqueId === "string"
? att.content.uniqueId.trim()
: "";
const fileName =
typeof att.content.fileName === "string"
? att.content.fileName.trim()
: "";
const fileType = typeof att.content.fileType === "string" ? att.content.fileType.trim() : "";
const uniqueId = typeof att.content.uniqueId === "string" ? att.content.uniqueId.trim() : "";
const fileName = typeof att.content.fileName === "string" ? att.content.fileName.trim() : "";
const fileHint =
name ||
fileName ||
(uniqueId && fileType ? `${uniqueId}.${fileType}` : "");
const fileHint = name || fileName || (uniqueId && fileType ? `${uniqueId}.${fileType}` : "");
return {
url: downloadUrl,
fileHint: fileHint || undefined,
@@ -65,8 +49,7 @@ function resolveDownloadCandidate(
};
}
const contentUrl =
typeof att.contentUrl === "string" ? att.contentUrl.trim() : "";
const contentUrl = typeof att.contentUrl === "string" ? att.contentUrl.trim() : "";
if (!contentUrl) return null;
return {
@@ -86,19 +69,10 @@ function scopeCandidatesForUrl(url: string): string[] {
host.endsWith("1drv.ms") ||
host.includes("sharepoint");
return looksLikeGraph
? [
"https://graph.microsoft.com/.default",
"https://api.botframework.com/.default",
]
: [
"https://api.botframework.com/.default",
"https://graph.microsoft.com/.default",
];
? ["https://graph.microsoft.com/.default", "https://api.botframework.com/.default"]
: ["https://api.botframework.com/.default", "https://graph.microsoft.com/.default"];
} catch {
return [
"https://api.botframework.com/.default",
"https://graph.microsoft.com/.default",
];
return ["https://api.botframework.com/.default", "https://graph.microsoft.com/.default"];
}
}
@@ -111,8 +85,7 @@ async function fetchWithAuthFallback(params: {
const firstAttempt = await fetchFn(params.url);
if (firstAttempt.ok) return firstAttempt;
if (!params.tokenProvider) return firstAttempt;
if (firstAttempt.status !== 401 && firstAttempt.status !== 403)
return firstAttempt;
if (firstAttempt.status !== 401 && firstAttempt.status !== 403) return firstAttempt;
const scopes = scopeCandidatesForUrl(params.url);
for (const scope of scopes) {

View File

@@ -1,12 +1,7 @@
import { detectMime } from "../../media/mime.js";
import { saveMediaBuffer } from "../../media/store.js";
import { downloadMSTeamsImageAttachments } from "./download.js";
import {
GRAPH_ROOT,
isRecord,
normalizeContentType,
resolveAllowedHosts,
} from "./shared.js";
import { GRAPH_ROOT, isRecord, normalizeContentType, resolveAllowedHosts } from "./shared.js";
import type {
MSTeamsAccessTokenProvider,
MSTeamsAttachmentLike,
@@ -29,18 +24,13 @@ type GraphAttachment = {
content?: unknown;
};
function readNestedString(
value: unknown,
keys: Array<string | number>,
): string | undefined {
function readNestedString(value: unknown, keys: Array<string | number>): string | undefined {
let current: unknown = value;
for (const key of keys) {
if (!isRecord(current)) return undefined;
current = current[key as keyof typeof current];
}
return typeof current === "string" && current.trim()
? current.trim()
: undefined;
return typeof current === "string" && current.trim() ? current.trim() : undefined;
}
export function buildMSTeamsGraphMessageUrls(params: {
@@ -63,8 +53,7 @@ export function buildMSTeamsGraphMessageUrls(params: {
pushCandidate(readNestedString(params.channelData, ["messageId"]));
pushCandidate(readNestedString(params.channelData, ["teamsMessageId"]));
const replyToId =
typeof params.replyToId === "string" ? params.replyToId.trim() : "";
const replyToId = typeof params.replyToId === "string" ? params.replyToId.trim() : "";
if (conversationType === "channel") {
const teamId =
@@ -84,8 +73,7 @@ export function buildMSTeamsGraphMessageUrls(params: {
);
}
}
if (messageIdCandidates.size === 0 && replyToId)
messageIdCandidates.add(replyToId);
if (messageIdCandidates.size === 0 && replyToId) messageIdCandidates.add(replyToId);
for (const candidate of messageIdCandidates) {
urls.push(
`${GRAPH_ROOT}/teams/${encodeURIComponent(teamId)}/channels/${encodeURIComponent(channelId)}/messages/${encodeURIComponent(candidate)}`,
@@ -94,12 +82,9 @@ export function buildMSTeamsGraphMessageUrls(params: {
return Array.from(new Set(urls));
}
const chatId =
params.conversationId?.trim() ||
readNestedString(params.channelData, ["chatId"]);
const chatId = params.conversationId?.trim() || readNestedString(params.channelData, ["chatId"]);
if (!chatId) return [];
if (messageIdCandidates.size === 0 && replyToId)
messageIdCandidates.add(replyToId);
if (messageIdCandidates.size === 0 && replyToId) messageIdCandidates.add(replyToId);
const urls = Array.from(messageIdCandidates).map(
(candidate) =>
`${GRAPH_ROOT}/chats/${encodeURIComponent(chatId)}/messages/${encodeURIComponent(candidate)}`,
@@ -161,8 +146,7 @@ async function downloadGraphHostedImages(params: {
const out: MSTeamsInboundMedia[] = [];
for (const item of hosted.items) {
const contentBytes =
typeof item.contentBytes === "string" ? item.contentBytes : "";
const contentBytes = typeof item.contentBytes === "string" ? item.contentBytes : "";
if (!contentBytes) continue;
let buffer: Buffer;
try {
@@ -208,9 +192,7 @@ export async function downloadMSTeamsGraphMedia(params: {
const messageUrl = params.messageUrl;
let accessToken: string;
try {
accessToken = await params.tokenProvider.getAccessToken(
"https://graph.microsoft.com/.default",
);
accessToken = await params.tokenProvider.getAccessToken("https://graph.microsoft.com/.default");
} catch {
return { media: [], messageUrl, tokenError: true };
}

View File

@@ -6,10 +6,7 @@ import {
isLikelyImageAttachment,
safeHostForUrl,
} from "./shared.js";
import type {
MSTeamsAttachmentLike,
MSTeamsHtmlAttachmentSummary,
} from "./types.js";
import type { MSTeamsAttachmentLike, MSTeamsHtmlAttachmentSummary } from "./types.js";
export function summarizeMSTeamsHtmlAttachments(
attachments: MSTeamsAttachmentLike[] | undefined,

View File

@@ -61,9 +61,7 @@ export function inferPlaceholder(params: {
const fileType = params.fileType?.toLowerCase() ?? "";
const looksLikeImage =
mime.startsWith("image/") ||
IMAGE_EXT_RE.test(name) ||
IMAGE_EXT_RE.test(`x.${fileType}`);
mime.startsWith("image/") || IMAGE_EXT_RE.test(name) || IMAGE_EXT_RE.test(`x.${fileType}`);
return looksLikeImage ? "<media:image>" : "<media:document>";
}
@@ -78,11 +76,9 @@ export function isLikelyImageAttachment(att: MSTeamsAttachmentLike): boolean {
contentType === "application/vnd.microsoft.teams.file.download.info" &&
isRecord(att.content)
) {
const fileType =
typeof att.content.fileType === "string" ? att.content.fileType : "";
const fileType = typeof att.content.fileType === "string" ? att.content.fileType : "";
if (fileType && IMAGE_EXT_RE.test(`x.${fileType}`)) return true;
const fileName =
typeof att.content.fileName === "string" ? att.content.fileName : "";
const fileName = typeof att.content.fileName === "string" ? att.content.fileName : "";
if (fileName && IMAGE_EXT_RE.test(fileName)) return true;
}
@@ -94,9 +90,7 @@ function isHtmlAttachment(att: MSTeamsAttachmentLike): boolean {
return contentType.startsWith("text/html");
}
export function extractHtmlFromAttachment(
att: MSTeamsAttachmentLike,
): string | undefined {
export function extractHtmlFromAttachment(att: MSTeamsAttachmentLike): string | undefined {
if (!isHtmlAttachment(att)) return undefined;
if (typeof att.content === "string") return att.content;
if (!isRecord(att.content)) return undefined;
@@ -194,9 +188,7 @@ export function resolveAllowedHosts(input?: string[]): string[] {
function isHostAllowed(host: string, allowlist: string[]): boolean {
if (allowlist.includes("*")) return true;
const normalized = host.toLowerCase();
return allowlist.some(
(entry) => normalized === entry || normalized.endsWith(`.${entry}`),
);
return allowlist.some((entry) => normalized === entry || normalized.endsWith(`.${entry}`));
}
export function isUrlAllowed(url: string, allowlist: string[]): boolean {