Merge pull request #1702 from PR0M3TH3AN/codex/inspect-connection-handling-for-uploads

Normalize storage connection public URLs for uploads
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-01-25 20:54:30 -05:00
commit 9b38b55542
2 files changed
+47 -3

No files matched your search

+9
View File
@@ -769,6 +769,15 @@ class R2Service {
const accessKeyId = (effectiveSettings.accessKeyId || "").trim();
const secretAccessKey = (effectiveSettings.secretAccessKey || "").trim();
devLogger.debug("[R2] prepareUpload resolved settings", {
provider: effectiveSettings.provider || "",
accountId: accountId ? truncateMiddle(accountId, 6) : "",
bucket: effectiveSettings.bucket || "",
baseDomain: effectiveSettings.baseDomain || "",
publicBaseUrl: effectiveSettings.publicBaseUrl || "",
isLegacy: effectiveSettings.isLegacy !== false,
});
if (!accountId || !accessKeyId || !secretAccessKey) {
throw new Error("Missing R2 credentials. Unlock your storage or save settings.");
}
+38 -3
View File
@@ -50,6 +50,32 @@ function resolveEndpoint(config) {
return config.endpoint || resolveConnectionMeta(config).endpoint;
}
function resolvePublicBaseUrl(config) {
const meta = resolveConnectionMeta(config);
return (
config.publicBaseUrl ||
config.baseDomain ||
config.publicUrl ||
meta.publicBaseUrl ||
meta.baseDomain ||
meta.publicUrl ||
meta.publicAccessUrl ||
meta.publicBucketUrl ||
""
);
}
function normalizeConnectionMeta(meta = {}, config = {}) {
const normalized = { ...meta };
const publicBaseUrl = resolvePublicBaseUrl({ ...config, meta });
if (publicBaseUrl) {
normalized.publicBaseUrl = publicBaseUrl;
normalized.baseDomain = publicBaseUrl;
normalized.publicUrl = publicBaseUrl;
}
return normalized;
}
function resolveR2Endpoint(config) {
const accountId =
config.accountId || resolveConnectionMeta(config).accountId || "";
@@ -78,7 +104,7 @@ function buildS3TestConfig(config, overrides = {}) {
region: resolveRegion(config),
endpoint: resolveEndpoint(config),
forcePathStyle: resolveForcePathStyle(config),
publicBaseUrl: config.publicBaseUrl,
publicBaseUrl: resolvePublicBaseUrl(config),
...overrides,
};
}
@@ -414,6 +440,7 @@ export class StorageService {
const masterKey = this.masterKeys.get(pubkey);
const encrypted = await this._encryptPayload(payload, masterKey);
const account = (await this._getAccount(pubkey)) || { pubkey, connections: {} };
const normalizedMeta = normalizeConnectionMeta(meta, payload);
if (!account.connections) {
account.connections = {};
@@ -433,7 +460,7 @@ export class StorageService {
id: connectionId,
provider: payload.provider || meta.provider,
meta: {
...meta,
...normalizedMeta,
lastSaved: Date.now(),
provider: payload.provider || meta.provider,
},
@@ -460,10 +487,18 @@ export class StorageService {
const masterKey = this.masterKeys.get(pubkey);
const payload = await this._decryptPayload(conn.encrypted, masterKey);
const normalizedMeta = normalizeConnectionMeta(conn.meta, payload);
const publicBaseUrl = resolvePublicBaseUrl({
...payload,
meta: normalizedMeta,
});
const baseDomain = publicBaseUrl || payload.baseDomain || normalizedMeta.baseDomain || "";
return {
...payload,
meta: conn.meta,
publicBaseUrl,
baseDomain,
meta: normalizedMeta,
};
}