File size: 1,670 Bytes
1f074d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 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;
}