feat: scripts

This commit is contained in:
2025-04-05 16:57:26 +08:00
parent bd4fe63cdc
commit 3e996ffab3
62 changed files with 4905 additions and 0 deletions

60
scripts/ossuploader.js Normal file
View File

@@ -0,0 +1,60 @@
#! /usr/bin/env runjs
var oss = require('component-oss.js');
var args = require('component-args.js');
var counter = require('component-counter.js');
oss.requireJARs();
var main = () => {
var start = $$.date().millis();
var parsedArgs = args.parseARGS();
if ((parsedArgs.args.length < 1) || (!(parsedArgs.values['config']))) {
println('Config file or file is not assigned.');
println('ossuploader.js --config config.json filename.ext [target_filename.ext]');
return;
}
try {
var config = $$.rFile(parsedArgs.values['config']).string();
configJSON = JSON.parse(config);
} catch (e) {
println('Parse config error: ' + e);
}
if (!configJSON || !configJSON.bucket || !configJSON.endpoint || !configJSON.accessKey || !configJSON.secretKey) {
println('----- Config format -----');
println('{');
println(' \"endpoint\": \"<ENDPOINT>\",');
println(' \"bucket\": \"<BUCKET>\",');
println(' \"accessKey\": \"<AK>\",');
println(' \"secretKey\": \"<SK>\",');
println('}');
return;
}
println('OSS info: ' + configJSON.bucket + '@' + configJSON.endpoint);
oss.newClient(configJSON.endpoint, configJSON.accessKey, configJSON.secretKey).runWith((client) => {
if (!client.doesBucketExist(configJSON.bucket)) {
println("Bucket NOT exists: " + configJSON.bucket);
return;
}
var localFile = parsedArgs.args[0];
var remoteFile = parsedArgs.args[1] || parsedArgs.args[0].replace(/[^a-zA-Z0-9\.\-]/, '_');
println('Uploading file: ' + localFile + ' -> ' + remoteFile);
var counterIS = oss.createCounterIS(localFile);
client.putObject(configJSON.bucket, remoteFile, counterIS);
println();
counterIS.close();
println('Upload file finished, cost: ' + ($$.date().millis() - start) + ' ms.');
});
};
main();