Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/base/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ export function basename(path: string | URL) {
return path.split("/").at(-1)!;
}

export function extension(path: string) {
return path.split(".").at(-1) ?? "";
export function extension(path: string): string {
const res = path.split(".");
if (res.length <= 1) {
return "";
}
return res.at(-1)!;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/kicanvas/services/codeberg-vfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export class CodebergFileSystem extends FileSystemBase {
it.type === "file" &&
CodebergFileSystem.is_kicad_file(it.name)
) {
const file_path = based_on(base_dir, it.path);
const path = decodeURI(it.path);
const file_path = based_on(base_dir, path);

this.download_urls.set(file_path, new URL(it.git_url));

Expand All @@ -74,9 +75,12 @@ export class CodebergFileSystem extends FileSystemBase {
path: file_path,
});
} else if (it.type === "dir") {
const path = decodeURI(it.path);
const dir_path = based_on(base_dir, path);

result.push({
type: "directory",
path: based_on(base_dir, it.path),
path: dir_path,
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/kicanvas/services/codeberg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Codeberg {
return null;
}

const path_parts = url.pathname.split("/");
const path_parts = url.pathname.split("/").map((s) => decodeURI(s));

if (path_parts.length < 3) {
return null;
Expand Down
15 changes: 11 additions & 4 deletions src/kicanvas/services/github-vfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export class GitHubFileSystem extends FileSystemBase {
const result: FileEntry[] = [];
for (const it of contents) {
if (it.type === "file" && GitHubFileSystem.is_kicad_file(it.name)) {
const file_path = based_on(base_dir, it.path);
const path = decodeURI(it.path);
const file_path = based_on(base_dir, path);

this.download_urls.set(file_path, new URL(it.download_url));

Expand All @@ -82,9 +83,12 @@ export class GitHubFileSystem extends FileSystemBase {
path: file_path,
});
} else if (it.type === "dir") {
const path = decodeURI(it.path);
const dir_path = based_on(base_dir, path);

result.push({
type: "directory",
path: based_on(base_dir, it.path),
path: dir_path,
});
}
}
Expand All @@ -110,12 +114,15 @@ export class GitHubFileSystem extends FileSystemBase {
// If it's one file just load one file.
let single_file = false;
if (info.type === "blob") {
if (["kicad_sch", "kicad_pcb"].includes(extension(info.path!))) {
const ext_name = extension(info.path!);
if (["kicad_sch", "kicad_pcb"].includes(ext_name)) {
single_file = true;
} else {
// Link to non-kicad file, try using the containing directory.
info.type = "tree";
info.path = dirname(info.path!);
if (ext_name.length !== 0) {
info.path = dirname(info.path!);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/kicanvas/services/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class GitHub {
return null;
}

const path_parts = url.pathname.split("/");
const path_parts = url.pathname.split("/").map((s) => decodeURI(s));

if (path_parts.length < 3) {
return null;
Expand Down
Loading