kenken999's picture
test
1f074d8
raw
history blame
1.67 kB
// This script handles the image search system
// Configuration
var SECRET_KEY = 'YOUR_SECRET_KEY';
var S3_BUCKET = 'YOUR_S3_BUCKET';
var DRIVE_FOLDER = 'YOUR_DRIVE_FOLDER';
// Function to handle doPost requests
function doPost(e) {
var type = e.parameter.type;
var data = e.parameter.data;
if (type == 'image') {
// Save image to Drive
var driveFolder = DriveApp.getFolderById(DRIVE_FOLDER);
var file = driveFolder.createFile(data);
var fileId = file.getId();
// Upload to S3
var s3 = getS3();
s3.putObject({
Bucket: S3_BUCKET,
Key: fileId,
Body: file.getBlob()
});
}
}
// Function to get S3 instance
function getS3() {
var s3 = UrlFetchApp.fetch('https://s3.amazonaws.com/', {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + SECRET_KEY
}
});
return s3;
}
// Function to generate PlantUML flow diagram
function generateFlowDiagram() {
var flow = '@startuml\n';
flow += 'participant "Line" as line\n';
flow += 'participant "Google Apps Script" as gas\n';
flow += 'participant "Drive" as drive\n';
flow += 'participant "S3" as s3\n';
flow += 'line->gas: doPost\n';
flow += 'gas->drive: save image\n';
flow += 'gas->s3: upload image\n';
flow += '@enduml';
return flow;
}
// Function to generate system documentation
function generateSystemDocumentation() {
var doc = 'Image Search System Documentation\n';
doc += '=================================\n';
doc += 'This system handles image search requests from Line and saves the images to Drive and uploads them to S3.\n';
doc += 'System Flow:\n';
doc += generateFlowDiagram();
return doc;
}