@xuda.io/drive_module 1.1.1503 → 1.1.1504
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +55 -0
- package/index_ms.mjs +4 -0
- package/index_msa.mjs +4 -0
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -5185,3 +5185,58 @@ export const drive_set_plan = async function (req) {
|
|
|
5185
5185
|
return { code: -1, data: err.message || String(err) };
|
|
5186
5186
|
}
|
|
5187
5187
|
};
|
|
5188
|
+
|
|
5189
|
+
// ---------------------------------------------------------------------------
|
|
5190
|
+
// PLATFORM ARTIFACTS
|
|
5191
|
+
// ---------------------------------------------------------------------------
|
|
5192
|
+
// Uploads a platform-owned file (not a customer drive file) and returns a URL
|
|
5193
|
+
// that a third party can fetch for a short window. Built for the app bundler:
|
|
5194
|
+
// create_app_bundle writes a tree to a local directory, and a macOS build runs
|
|
5195
|
+
// on Codemagic's machine, so the archive has to be reachable from outside.
|
|
5196
|
+
//
|
|
5197
|
+
// Lives here because drive_module owns the R2 client, the bucket map and the
|
|
5198
|
+
// credentials. Nothing else should be constructing S3 clients.
|
|
5199
|
+
//
|
|
5200
|
+
// SIGNED, not public. There is no r2.public_base configured, so an uploaded
|
|
5201
|
+
// object has no public URL at all, and giving the bucket one would make every
|
|
5202
|
+
// object in it world-readable to solve a problem that is really "let one machine
|
|
5203
|
+
// read one file for ten minutes". A presigned URL keeps the bucket private and
|
|
5204
|
+
// expires on its own.
|
|
5205
|
+
export const upload_platform_artifact = async function ({ file_path, key, expires_in = 900, content_type = 'application/gzip' }) {
|
|
5206
|
+
if (!file_path || !fs.existsSync(file_path)) {
|
|
5207
|
+
return { code: -2, data: `artifact not found: ${file_path}` };
|
|
5208
|
+
}
|
|
5209
|
+
if (!key) return { code: -2, data: 'key is mandatory' };
|
|
5210
|
+
|
|
5211
|
+
const region_host = process.env.XUDA_HOSTNAME;
|
|
5212
|
+
const conf = _conf.storage_bucket?.[region_host];
|
|
5213
|
+
const s3 = _drive_s3_for(region_host);
|
|
5214
|
+
if (!s3 || !conf) return { code: -2, data: `no storage config for ${region_host}` };
|
|
5215
|
+
|
|
5216
|
+
// Imported lazily and on purpose: @aws-sdk/s3-request-presigner is a separate
|
|
5217
|
+
// package from client-s3, so a box that has not installed it would otherwise
|
|
5218
|
+
// fail to LOAD drive_module rather than fail this one call.
|
|
5219
|
+
let getSignedUrl;
|
|
5220
|
+
try {
|
|
5221
|
+
({ getSignedUrl } = await import('@aws-sdk/s3-request-presigner'));
|
|
5222
|
+
} catch (err) {
|
|
5223
|
+
return { code: -2, data: 'missing dependency @aws-sdk/s3-request-presigner, run npm install in cpi/' };
|
|
5224
|
+
}
|
|
5225
|
+
|
|
5226
|
+
const Bucket = conf.name;
|
|
5227
|
+
const Key = `platform_artifacts/${String(key).replace(/^\/+/, '')}`;
|
|
5228
|
+
|
|
5229
|
+
try {
|
|
5230
|
+
const upload = new Upload({
|
|
5231
|
+
client: s3,
|
|
5232
|
+
params: { Bucket, Key, Body: fs.createReadStream(file_path), ContentType: content_type },
|
|
5233
|
+
});
|
|
5234
|
+
await upload.done();
|
|
5235
|
+
|
|
5236
|
+
const url = await getSignedUrl(s3, new GetObjectCommand({ Bucket, Key }), { expiresIn: expires_in });
|
|
5237
|
+
|
|
5238
|
+
return { code: 1, data: { url, key: Key, bucket: Bucket, expires_in, bytes: fs.statSync(file_path).size } };
|
|
5239
|
+
} catch (err) {
|
|
5240
|
+
return { code: -1, data: `artifact upload failed: ${err.message}` };
|
|
5241
|
+
}
|
|
5242
|
+
};
|
package/index_ms.mjs
CHANGED
|
@@ -441,6 +441,10 @@ export const drive_set_plan = async function (...args) {
|
|
|
441
441
|
return await broker.send_to_queue("drive_set_plan", ...args);
|
|
442
442
|
};
|
|
443
443
|
|
|
444
|
+
export const upload_platform_artifact = async function (...args) {
|
|
445
|
+
return await broker.send_to_queue("upload_platform_artifact", ...args);
|
|
446
|
+
};
|
|
447
|
+
|
|
444
448
|
export const get_drive_files_studio = async function (...args) {
|
|
445
449
|
return await broker.send_to_queue("get_drive_files_studio", ...args);
|
|
446
450
|
};
|
package/index_msa.mjs
CHANGED
|
@@ -441,6 +441,10 @@ export const drive_set_plan = function (...args) {
|
|
|
441
441
|
broker.send_to_queue_async("drive_set_plan", ...args);
|
|
442
442
|
};
|
|
443
443
|
|
|
444
|
+
export const upload_platform_artifact = function (...args) {
|
|
445
|
+
broker.send_to_queue_async("upload_platform_artifact", ...args);
|
|
446
|
+
};
|
|
447
|
+
|
|
444
448
|
export const get_drive_files_studio = function (...args) {
|
|
445
449
|
broker.send_to_queue_async("get_drive_files_studio", ...args);
|
|
446
450
|
};
|