Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* limitations under the License.
*/
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname,
// my-src-bucketname and my-src-objectname are dummy values, please replace
// them with original values.
var Minio = require('minio')
var s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY'
})
var conds = new Minio.CopyConditions()
conds.setMatchETag('bd891862ea3e22c93ed53a098218791d')
s3Client.copyObject('my-bucketname', 'my-objectname', '/my-src-bucketname/my-src-objectname', conds, function(e, data) {
if (e) {
return console.log(e)
}
console.log("Successfully copied the object:")
console.log("etag = " + data.etag + ", lastModified = " + data.lastModified)
})
throw new Error(`A verifier for type '${type}' hasn't been defined.`);
}
if (type !== fName.type) {
throw new Error(`FileTypes do not match. Have you changed the fileName? The type should be '${type}'`);
}
try {
stat = yield this.client.statObject(this.fileStorageConfig.bucket, fName.uploadName);
}
catch (e) {
if (e.message.toLowerCase().indexOf("not found") >= 0) {
throw new Error("Please upload a file before verifying.");
}
throw e;
}
const verifyFileName = fName.createTempName();
const verifyCopyConditions = new Minio.CopyConditions();
verifyCopyConditions.setMatchETag(stat.etag);
yield this.client.copyObject(this.fileStorageConfig.bucket, verifyFileName, `/${this.fileStorageConfig.bucket}/${fName.uploadName}`, verifyCopyConditions);
yield this.verifierObjects[type].verify(verifyFileName, fName);
yield this.auth.userQuery(context.accessToken, "SELECT _meta.file_verify($1);", [fName.id]);
// Try to clean up temp objects. However, don't care if it fails.
try {
yield this.client.removeObjects(this.fileStorageConfig.bucket, [fName.uploadName, verifyFileName]);
}
catch (err) {
this.logger.warn("verifyFile.removeObjectsFail", err);
}
const verifier = this.verifierObjects[fName.type];
const objectNames = verifier.getObjectNames(fName);
const cacheSettings = verifier.getObjectCacheSettings(fName);
const objects = objectNames.map((object) => {
return {
public async verify(verifyFileName: string, fileName: FileName) {
try {
const stat = await this.client.statObject(this.bucket, verifyFileName);
const copyConditions = new Minio.CopyConditions();
copyConditions.setMatchETag(stat.etag);
await this.client.copyObject(this.bucket, fileName.name, `/${this.bucket}/${verifyFileName}`, copyConditions);
} catch (e) {
if (e.message.toLowerCase().indexOf("not found") >= 0) {
throw new Error("Please upload a file before verifying.");
}
throw e;
}
}
if (type !== fileName.type) {
throw new UserInputError(`FileTypes do not match. Have you changed the fileName? The type should be '${type}'`, { exposeDetails: true });
}
try {
stat = await this.client.statObject(this.fileStorageConfig.bucket, fileName.uploadName);
} catch (e) {
if (e.message.toLowerCase().indexOf("not found") >= 0) {
throw new UserInputError("Please upload a file before verifying.", { exposeDetails: true });
}
throw e;
}
const verifyFileName = fileName.createTempName();
const verifyCopyConditions = new Minio.CopyConditions();
verifyCopyConditions.setMatchETag(stat.etag);
await this.client.copyObject(
this.fileStorageConfig.bucket,
verifyFileName,
`/${this.fileStorageConfig.bucket}/${fileName.uploadName}`,
verifyCopyConditions
);
await this.verifierObjects[type].verify(verifyFileName, fileName);
if (accessToken != null) {
await this.auth.getAuthQueryHelper().userQuery(accessToken, "SELECT _meta.file_verify($1);", [fileName.id]);
} else {
await this.auth.getAuthQueryHelper().query("SELECT _meta.file_verify($1);", [fileName.id]);
}
return __awaiter(this, void 0, void 0, function* () {
try {
const stat = yield this.client.statObject(this.bucket, verifyFileName);
const copyConditions = new Minio.CopyConditions();
copyConditions.setMatchETag(stat.etag);
yield this.client.copyObject(this.bucket, fName.name, `/${this.bucket}/${verifyFileName}`, copyConditions);
}
catch (e) {
if (e.message.toLowerCase().indexOf("not found") >= 0) {
throw new Error("Please upload a file before verifying.");
}
throw e;
}
});
}