--- title: Artify api tags: artify --- [TOC] # account ## 註冊 api ### 規劃 - 帳號使用 email - 密碼不限制 - 帳號也在 fio 建立一個帳號 - 在 FiO 建立的帳號沒有密碼 ### BDD 1. 檢查帳號是否為空值 2. 檢查帳號是否是 email 3. 將帳號轉成小寫 4. 檢查帳號是否重複 5. 將密碼用 md5 加密 要加鹽巴 - pwd = md5(明文 + process.鹽巴) - 正式站、測試站鹽巴先用同一個,比較方便開發及測試 6. 存入 artify 資料庫 - collection: `account` 7. 打 FiO api 將帳號加入 FiO 資料庫 - FiO API: `xxxx` ### 資料格式 - account ```sql= { _id: int username: string, password: string, profile: { // 註冊時不會有 name: ... } created_at: Date, updated_at: Date } ``` ## 登入 api ### 規劃 - 照著 FiO 做 - 使用 cookie-session - 要訂 cookie name 預設是 express:sess - 預設不改 - 要訂 cookie.domain - 正式站:config.cookie.domain - artify.one - front-end: artify.one - backend: api.artify.one - 測試站:config.cookie.domain - test.artify.one - front-end: test.artify.one - back-end: api.test.artify.one ### BDD 1. 檢查帳號密碼是否為空值 2. 將帳號轉成小寫 3. 將密碼用 md5 加密 4. 將帳號, 密碼 到資料庫比對 5. 將帳號加入 req.session // 身份 type? 是否存入 ? - 前端需要什麼資料? - username || email ## 上傳圖片 (大頭貼與 NFT) api ### 規劃 - 同時上傳到 server 與 IPFS - server 上儲存圖片的資料夾分成 product / avatar - 檔案路徑需在前方 prefix 加入到 config - 檔案名稱撞名的風險 => hash 檔名 或 加日期 - 2020-11-22-${hash}.xxx - config.upload - product - avatar - example: config.uplaod + '/product/xxx.jpg' - example: config.uplaod + '/avatar/xxxx.jpg' - 使用套件 multiparty - NFT: - 上傳 IPFS 打 FiO api 拿 cid ### BDD 1. 檢查檔案大小 不能超過 15MB 2. fs.rename() hash 檔名 並更改路徑至相對應的資料夾 3. 呼叫 FiO API - product - NFT - 呼叫 FiO API 取得 cid - 不加密 - 大頭貼: 不呼叫 4. 回傳資料 ### Edit profile api ### ipfs api 不加密 ### 開 FiO app ```javascript= // build an NFTCreator const rsObj = await Post.json('https://dev.fio.one/api/v1/app/subscribe', {solution: "NFTFiODemo"},{"x-api-key": "AjoiyvQBFlzWyijBMCFF7QG5dPDBieMZ", "token": "35f53f325bb5e9f3f0f0b22eaf354d6a"}); if (rsObj.code !== 0) return res.err(3, "Fail to subscribe FiO's nft app"); const fio_id = rsObj.data.fio_id; ```