# 🚀 Google Apps Script File Upload API (含網址回傳)

本 API 允許前端透過 POST 請求將檔案上傳至 Google Drive 指定資料夾，上傳完成後會回傳該檔案的 **公開瀏覽/下載網址**。

## 1. 基本資訊
- **Endpoint URL**: `https://script.google.com/macros/s/[YOUR_DEPLOYMENT_ID]/exec`
- **Method**: `POST`
- **Authentication**: `username` & `password` 比對。

---

## 2. 請求參數 (Request Body)
| 欄位名稱 | 說明 |
| :--- | :--- |
| **`username`** | 使用者帳號 |
| **`password`** | 使用者密碼 |
| **`fileName`** | 檔案名稱（例如：`photo.jpg`） |
| **`mimeType`** | MIME 類型（例如：`image/jpeg`） |
| **`file`** | **Base64** 字串內容 |

---

## 3. 回傳格式 (Response)

### ✅ 成功回傳 (包含檔案網址)
```json
{
  "status": "success",
  "message": "檔案上傳成功！",
  "fileUrl": "[https://drive.google.com/file/d/1A2B3C.../view?usp=drivesdk](https://drive.google.com/file/d/1A2B3C.../view?usp=drivesdk)"
}
```
> **註**：`fileUrl` 可直接用於前端展示或提供給使用者下載。

### ❌ 失敗回傳
```json
{
  "status": "error",
  "message": "帳號或密碼錯誤"
}
```

---

## 4. 前端讀取網址範例
```javascript
const response = await fetch(API_URL, {
  method: 'POST',
  body: JSON.stringify(payload)
});

const result = await response.json();

if (result.status === "success") {
  console.log("檔案已儲存至雲端：" + result.fileUrl);
  // 你可以將 result.fileUrl 顯示在畫面上讓使用者點擊
}
```

---

## 5. 後端重點提醒
確保 `Code.gs` 中的回傳邏輯如下：
```javascript
const file = uploadFolder.createFile(blob);
return createJsonResponse({ 
  status: "success", 
  message: "檔案上傳成功！", 
  fileUrl: file.getUrl() // 取得檔案網址
});
```