驗證身份
This commit is contained in:
		@@ -39,6 +39,7 @@ func ImagesGet(w http.ResponseWriter, r *http.Request) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ImagesPost(w http.ResponseWriter, r *http.Request) {
 | 
					func ImagesPost(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
 | 
						models.AccountRead(w, r, func(account *models.Account) {
 | 
				
			||||||
		// 接收上傳的圖片文件, 僅限一張
 | 
							// 接收上傳的圖片文件, 僅限一張
 | 
				
			||||||
		file, file_header, err := r.FormFile("file")
 | 
							file, file_header, err := r.FormFile("file")
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
@@ -76,9 +77,10 @@ func ImagesPost(w http.ResponseWriter, r *http.Request) {
 | 
				
			|||||||
		img.Hash = fmt.Sprintf("%x", md5.Sum(content))                // 计算哈希
 | 
							img.Hash = fmt.Sprintf("%x", md5.Sum(content))                // 计算哈希
 | 
				
			||||||
		img.Type = file_header.Header.Get("Content-Type")             // 文件類型
 | 
							img.Type = file_header.Header.Get("Content-Type")             // 文件類型
 | 
				
			||||||
		img.Path = fmt.Sprintf("data/images/%s.%s", img.Hash, format) // 存儲路徑
 | 
							img.Path = fmt.Sprintf("data/images/%s.%s", img.Hash, format) // 存儲路徑
 | 
				
			||||||
	img.Width = imgData.Bounds().Dx()
 | 
							img.Width = imgData.Bounds().Dx()                             // 圖片寬度
 | 
				
			||||||
	img.Height = imgData.Bounds().Dy()
 | 
							img.Height = imgData.Bounds().Dy()                            // 圖片高度
 | 
				
			||||||
	img.Format = format
 | 
							img.Format = format                                           // 圖片格式
 | 
				
			||||||
 | 
							img.UserID = account.ID                                       // 用戶ID
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 先檢查 data/images 目錄是否存在
 | 
							// 先檢查 data/images 目錄是否存在
 | 
				
			||||||
		if _, err := ioutil.ReadDir("data/images"); err != nil {
 | 
							if _, err := ioutil.ReadDir("data/images"); err != nil {
 | 
				
			||||||
@@ -102,6 +104,7 @@ func ImagesPost(w http.ResponseWriter, r *http.Request) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		w.Header().Set("Content-Type", "application/json; charset=utf-8")
 | 
							w.Header().Set("Content-Type", "application/json; charset=utf-8")
 | 
				
			||||||
		w.Write(utils.ToJSON(img))
 | 
							w.Write(utils.ToJSON(img))
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ImagesItemGet(w http.ResponseWriter, r *http.Request) {
 | 
					func ImagesItemGet(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user