No longer use HEAD requests, which are handled oddly in Safari on iOS
This commit is contained in:
@@ -20,15 +20,27 @@ export class FallbackSpacePrimitives implements SpacePrimitives {
|
|||||||
async readFile(name: string): Promise<{ data: Uint8Array; meta: FileMeta }> {
|
async readFile(name: string): Promise<{ data: Uint8Array; meta: FileMeta }> {
|
||||||
try {
|
try {
|
||||||
return await this.primary.readFile(name);
|
return await this.primary.readFile(name);
|
||||||
} catch {
|
} catch (e) {
|
||||||
|
try {
|
||||||
return this.fallback.readFile(name);
|
return this.fallback.readFile(name);
|
||||||
|
} catch (fallbackError) {
|
||||||
|
console.error("Error during reaFile fallback", fallbackError);
|
||||||
|
// Fallback failed, so let's throw the original error
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async getFileMeta(name: string): Promise<FileMeta> {
|
async getFileMeta(name: string): Promise<FileMeta> {
|
||||||
try {
|
try {
|
||||||
return await this.primary.getFileMeta(name);
|
return await this.primary.getFileMeta(name);
|
||||||
} catch {
|
} catch (e) {
|
||||||
|
try {
|
||||||
return this.fallback.getFileMeta(name);
|
return this.fallback.getFileMeta(name);
|
||||||
|
} catch (fallbackError) {
|
||||||
|
console.error("Error during getFileMeta fallback", fallbackError);
|
||||||
|
// Fallback failed, so let's throw the original error
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writeFile(
|
writeFile(
|
||||||
|
|||||||
@@ -21,9 +21,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
|||||||
options.headers = { ...options.headers, ...{ "X-Sync-Mode": "true" } };
|
options.headers = { ...options.headers, ...{ "X-Sync-Mode": "true" } };
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await fetch(url, {
|
const result = await fetch(url, options);
|
||||||
...options,
|
|
||||||
});
|
|
||||||
if (result.redirected) {
|
if (result.redirected) {
|
||||||
// Got a redirect, we'll assume this is due to invalid credentials and redirecting to an auth page
|
// Got a redirect, we'll assume this is due to invalid credentials and redirecting to an auth page
|
||||||
console.log(
|
console.log(
|
||||||
@@ -118,8 +116,10 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
|||||||
async getFileMeta(name: string): Promise<FileMeta> {
|
async getFileMeta(name: string): Promise<FileMeta> {
|
||||||
const res = await this.authenticatedFetch(
|
const res = await this.authenticatedFetch(
|
||||||
`${this.url}/${encodeURI(name)}`,
|
`${this.url}/${encodeURI(name)}`,
|
||||||
|
// This used to use HEAD, but it seems that Safari on iOS is blocking cookies/credentials to be sent along with HEAD requests
|
||||||
|
// so we'll use GET instead and not use the body. A bit wasteful, but it works.
|
||||||
{
|
{
|
||||||
method: "HEAD",
|
method: "GET",
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (res.status === 404) {
|
if (res.status === 404) {
|
||||||
|
|||||||
Reference in New Issue
Block a user