mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-12-02 17:13:33 +01:00
fix(viewers): GitHub-style threads, one-unit authors, shared slots and tabs, gist formats
Review threads: one container in the code column with comments divided by rules; replies keep the first comment's indent (no nested cards). The Conversation tab uses the same thread. A fully redacted author renders as its slot alone, centred with the avatar and date. Slots outside rendered Markdown use the explorer's .redact-slot at the running-text alignment (.04em). PR and gist tabs drop the 2px transparent border so the shared #949 line spans the label and count and sits on the bar's rule. Gists: each file renders with the explorer's viewers (Markdown, code, notebook, CSV/TSV table, image, SVG, PDF, video, audio, binary and too-large states), with a Preview/Source toggle where they differ and Raw, copy and download. Binary gist files are now stored as base64 and passed through unchanged; images follow the "Display images" option. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
176bc857a1
commit
98bf382fa8
18 files changed
+541
-162
No files matched your search
+38
-8
@@ -15,7 +15,11 @@ import { IAnonymizedGistDocument } from "./model/anonymizedGists/anonymizedGists
|
||||
import AnonymizedGistModel from "./model/anonymizedGists/anonymizedGists.model";
|
||||
import config from "../config";
|
||||
import { octokit, ownerGitHubAccessRequired } from "./GitHubUtils";
|
||||
import { ContentAnonimizer } from "./anonymize-utils";
|
||||
import { ContentAnonimizer, classifyByName } from "./anonymize-utils";
|
||||
|
||||
// Binary gist files above this size are listed but not stored.
|
||||
const GIST_BINARY_LIMIT = 10 * 1024 * 1024;
|
||||
const isImageFile = (name: string) => /\.(png|jpe?g|gif|webp|bmp|ico|avif|tiff?)$/i.test(name || "");
|
||||
import { createLogger } from "./logger";
|
||||
|
||||
const logger = createLogger("gist");
|
||||
@@ -32,6 +36,8 @@ type GistPayload = {
|
||||
language?: string;
|
||||
size: number;
|
||||
type?: string;
|
||||
encoding?: "base64";
|
||||
tooLarge?: boolean;
|
||||
}[];
|
||||
comments: {
|
||||
body: string;
|
||||
@@ -110,6 +116,15 @@ export default class Gist {
|
||||
const files = await Promise.all(Object.values(gistInfo.data.files || {})
|
||||
.filter((f): f is NonNullable<typeof f> => !!f)
|
||||
.map(async (f) => {
|
||||
// Binary files (images, PDF, media) are kept byte for byte as base64:
|
||||
// they cannot be anonymized as text, and UTF-8 decoding corrupts them.
|
||||
if (f.filename && classifyByName(f.filename) === false) {
|
||||
const meta = { filename: f.filename, language: f.language || undefined, size: f.size || 0, type: f.type || undefined, encoding: "base64" as const };
|
||||
if ((f.size || 0) > GIST_BINARY_LIMIT || !f.raw_url) return { ...meta, content: "", tooLarge: (f.size || 0) > GIST_BINARY_LIMIT || undefined };
|
||||
const raw = await fetch(f.raw_url, { signal: AbortSignal.timeout(30000) });
|
||||
if (!raw.ok) throw new Error(`Gist file download failed (${raw.status})`);
|
||||
return { ...meta, content: Buffer.from(await raw.arrayBuffer()).toString("base64") };
|
||||
}
|
||||
let content = (f as typeof f & { encoding?: string }).encoding === "base64"
|
||||
? Buffer.from(f.content || "", "base64").toString("utf8")
|
||||
: f.content || "";
|
||||
@@ -335,13 +350,26 @@ export default class Gist {
|
||||
output.ownerLogin = anonymizer.anonymize(g?.ownerLogin || "");
|
||||
}
|
||||
if (this.options.content) {
|
||||
output.files = (g?.files || []).map((f) => ({
|
||||
filename: anonymizer.anonymize(f.filename),
|
||||
content: anonymizer.anonymize(f.content),
|
||||
language: f.language,
|
||||
size: f.size,
|
||||
type: f.type,
|
||||
}));
|
||||
output.files = (g?.files || []).map((f) => f.encoding === "base64"
|
||||
? {
|
||||
// Bytes pass through like a repository's binary files; images
|
||||
// follow the "Display images" option.
|
||||
filename: anonymizer.anonymize(f.filename),
|
||||
content: f.tooLarge || (this.options.image === false && isImageFile(f.filename)) ? undefined : f.content,
|
||||
language: f.language,
|
||||
size: f.size,
|
||||
type: f.type,
|
||||
encoding: "base64",
|
||||
tooLarge: f.tooLarge || undefined,
|
||||
hidden: this.options.image === false && isImageFile(f.filename) ? true : undefined,
|
||||
}
|
||||
: {
|
||||
filename: anonymizer.anonymize(f.filename),
|
||||
content: anonymizer.anonymize(f.content),
|
||||
language: f.language,
|
||||
size: f.size,
|
||||
type: f.type,
|
||||
});
|
||||
}
|
||||
if (this.options.comments) {
|
||||
output.comments = g?.comments?.map((comment) => {
|
||||
@@ -417,6 +445,8 @@ export default class Gist {
|
||||
language: f.language,
|
||||
size: f.size,
|
||||
type: f.type,
|
||||
encoding: f.encoding,
|
||||
tooLarge: f.tooLarge,
|
||||
})),
|
||||
comments: (g.comments || []).map((c) => ({
|
||||
body: c.body,
|
||||
|
||||
@@ -60,6 +60,9 @@ const AnonymizedGistSchema = new Schema({
|
||||
// nested `{ type: String }` the whole object is compiled as an array
|
||||
// of strings and file objects are silently dropped on save.
|
||||
type: { type: String },
|
||||
// Binary files (images, PDF, media) keep their bytes as base64.
|
||||
encoding: String,
|
||||
tooLarge: Boolean,
|
||||
},
|
||||
],
|
||||
comments: [
|
||||
|
||||
@@ -42,6 +42,8 @@ export interface IAnonymizedGist {
|
||||
language?: string;
|
||||
size?: number;
|
||||
type?: string;
|
||||
encoding?: "base64";
|
||||
tooLarge?: boolean;
|
||||
}[];
|
||||
comments?: {
|
||||
body: string;
|
||||
|
||||
Reference in new issue
Block a user