---
title: opencerts 檔名
tags: v2
---
# opencerts 檔名與 task name
## 需求
- 在下載 opencerts 檔案,可以知道檔名是什麼,並且下載後的檔名跟上傳時一樣
- cube_log 顯示整包一起上傳的記錄
## 現況
- 目前都是將透過 FiO API 將檔案上傳到 IPFS 後,將取得的 cid 打包進 opencerts 檔案來 issue,並沒有將檔名與 opencerts 檔案有關聯
## 需要考量
1. 純使用 API 串接的 user 要如何使用
2. 畫面上要如何呈現
3. 檔名要如何儲存
## opencerts 相關資料表
### tms opencerts_files
- schema
```=sql
{
_id: ObjectId
project_id: { type: Schema.Types.ObjectId, required: true, index: true },
cube_id: { type: Schema.Types.ObjectId, required: true, index: true },
owner_id: { type: Schema.Types.ObjectId, required: true, index: true },
draft_file_url: String,
issued_file_url: String,
blockchain: {
type: BlockchainSchema,
required: true,
},
transaction_hash: String,
directory_cid: String,
}
```
### fbms opencerts_task
- schema
```=sql
FileSchema: {
external_id: { type: String, required: true },
file_url: { type: String, required: true },
target_hash: String,
merkle_root: String,
}
{
_id: ObjectId
project_id: { type: Schema.Types.ObjectId, required: true, index: true },
files: [FileSchema],
blockchain: {
type: BlockchainSchema,
required: true,
},
state: {
type: String,
enum: [FILE_STATE.DOWNLOAD, FILE_STATE.ISSUE, FILE_STATE.UPLOAD],
default: FILE_STATE.DOWNLOAD,
},
status: {
type: String,
enum: [
COMMON_STATUS.PENDING,
COMMON_STATUS.PROCESSING,
COMMON_STATUS.SUCCESS,
COMMON_STATUS.FAILED,
],
default: COMMON_STATUS.PENDING,
},
transaction_hash: String,
webhook_url: { type: String, trim: true },
account_id: { type: Schema.Types.ObjectId },
wallet_id: { type: Schema.Types.ObjectId },
wallet_type: { type: String, enum: ['transaction', 'asset'] },
cid: String, // a cid directory of opencerts files
}
```
#### `opencerts_task` 的 `external_id` 等於 `opencerts_files` 的 `_id`
#### 上傳到 GCS 的檔名會改成 `opencerts_files` 的 `_id` 避免檔名重複
----
## Batch
- 多個檔案一次 task
- 頁面上會有一個 task_name 要輸入,為了在 cube_log 那邊可以看到他這批上傳的東西是什麼
- name 就是檔案的名字
## Multi
- 一個檔案就是一次 task
- 頁面上會有一個 file_name 要輸入,代表此次上傳的檔案名稱
## 問題
1. 顯示 cube_log 要如何知道他是同一次 task?
- 目前最多 32 個檔案一次 issue,opencerts 演算法的限制
- 每 32 個 transaction_hash issue 一次 transaction hash 會一樣
# conclusion
- 在 tms opencerts_file 新增欄位 `file_name` , `task_name` and `timestamp`
- 在 fbms issue 後回傳 timestamp
- file_name
- 用於下載 opencerts 檔案時,將檔案名稱改成跟當初一樣
- task_name
- 用於在 cube_log 顯示整包批次上傳的名稱
- timestamp
- 檔案超過 32 個一起 issue 的話,會自動切分成每 32 個 issue 一次,藉由 timestamp 可以用來辨別是否是屬於同一包檔
## API
### /api/v2/anti-fake-cube/draft
```=json
Input: {
"file_name": "micky-auth-file",
"tabs": [
{
"id": 1,
"tabname": "tab1",
"theme": "pdf",
"data": [
{
"type": "pdf",
"value": "bafkreid7juvuplxfv7cl6uiet2f3fw53sb2vncmhhyb5kcjezopoqxf7h4"
}
]
}
]
}
```
### /api/v2/anti-fake-cube/issue
```=josn
Input: {
"task_name": "mickyfan-batch",
"ids": [
"639aa0e6758c1565aea6fd51",
"639a9ca3014cc98ac715c968"
],
}
```