mirror of
https://github.com/silvanocerza/github-gitless-sync.git
synced 2026-07-22 12:10:28 +00:00
Fix mocked config dir and requestUrl
This commit is contained in:
parent
4f018043f2
commit
f2452b1c60
1 changed files with 13 additions and 37 deletions
|
|
@ -14,7 +14,7 @@ export class Vault {
|
||||||
|
|
||||||
constructor(rootPath: string) {
|
constructor(rootPath: string) {
|
||||||
this.rootPath = rootPath;
|
this.rootPath = rootPath;
|
||||||
this.configDir = path.join(this.rootPath, ".obsidian");
|
this.configDir = ".obsidian";
|
||||||
|
|
||||||
// Ensure vault directory exists
|
// Ensure vault directory exists
|
||||||
if (!existsSync(this.rootPath)) {
|
if (!existsSync(this.rootPath)) {
|
||||||
|
|
@ -22,8 +22,8 @@ export class Vault {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure config directory exists
|
// Ensure config directory exists
|
||||||
if (!existsSync(this.configDir)) {
|
if (!existsSync(path.join(this.rootPath, this.configDir))) {
|
||||||
mkdirSync(this.configDir, { recursive: true });
|
mkdirSync(path.join(this.rootPath, this.configDir), { recursive: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,41 +122,17 @@ interface RequestUrlParam {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function requestUrl(options: RequestUrlParam) {
|
export async function requestUrl(options: RequestUrlParam) {
|
||||||
try {
|
const response = await fetch(options.url, {
|
||||||
const response = await fetch(options.url, {
|
method: options.method || "GET",
|
||||||
method: options.method || "GET",
|
headers: options.headers,
|
||||||
headers: options.headers,
|
body: options.body,
|
||||||
body: options.body,
|
});
|
||||||
});
|
|
||||||
|
|
||||||
const arrayBuffer = await response.arrayBuffer();
|
// Convert to expected Obsidian response format
|
||||||
const text = new TextDecoder("utf-8").decode(arrayBuffer);
|
return {
|
||||||
let json = null;
|
status: response.status,
|
||||||
|
json: await response.json(),
|
||||||
json = JSON.parse(text);
|
};
|
||||||
|
|
||||||
// Convert to expected Obsidian response format
|
|
||||||
const obsidianResponse = {
|
|
||||||
status: response.status,
|
|
||||||
json: () => Promise.resolve(json),
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const err = new Error(`Request failed with status ${response.status}`);
|
|
||||||
err.response = obsidianResponse;
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
|
|
||||||
return obsidianResponse;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response) {
|
|
||||||
// Error already formatted with Obsidian response
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Network error or other fetch error
|
|
||||||
throw new Error(`Request failed: ${error.message}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mock utility functions
|
// Mock utility functions
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue