소스 검색

still works

Josh Yan 10 달 전
부모
커밋
736ad6f438
3개의 변경된 파일15개의 추가작업 그리고 25개의 파일을 삭제
  1. 1 5
      api/client.go
  2. 11 7
      cmd/cmd.go
  3. 3 13
      server/routes.go

+ 1 - 5
api/client.go

@@ -358,11 +358,7 @@ func (c *Client) Embeddings(ctx context.Context, req *EmbeddingRequest) (*Embedd
 
 // CreateBlob creates a blob from a file on the server. digest is the
 // expected SHA256 digest of the file, and r represents the file.
-func (c *Client) CreateBlob(ctx context.Context, digest string, local bool, r io.Reader) error {
-	headers := make(http.Header)
-	if local {
-		headers.Set("X-Redirect-Create", "1")
-	}
+func (c *Client) CreateBlob(ctx context.Context, digest string, r io.Reader) error {
 	return c.do(ctx, http.MethodPost, fmt.Sprintf("/api/blobs/%s", digest), r, nil)
 }
 

+ 11 - 7
cmd/cmd.go

@@ -265,6 +265,8 @@ func tempZipFiles(path string) (string, error) {
 	return tempfile.Name(), nil
 }
 
+var ErrBlobExists = errors.New("blob exists")
+
 func createBlob(cmd *cobra.Command, client *api.Client, path string) (string, error) {
 	bin, err := os.Open(path)
 	if err != nil {
@@ -311,15 +313,15 @@ func createBlob(cmd *cobra.Command, client *api.Client, path string) (string, er
 	} */
 	if client.IsLocal() {
 		config, err := getLocalPath(cmd.Context(), digest)
-		if err != nil {
-			return "", err
-		}
 
-		if config == nil {
-			fmt.Println("config is nil")
+		if errors.Is(err, ErrBlobExists) {
 			return digest, nil
 		}
 
+		if err != nil {
+			return "", err
+		}
+
 		fmt.Println("HI")
 		dest := config.ModelDir
 		fmt.Println("dest is ", dest)
@@ -333,7 +335,7 @@ func createBlob(cmd *cobra.Command, client *api.Client, path string) (string, er
 	}
 
 	fmt.Println("DEFAULT")
-	if err = client.CreateBlob(cmd.Context(), digest, false, bin); err != nil {
+	if err = client.CreateBlob(cmd.Context(), digest, bin); err != nil {
 		return "", err
 	}
 	return digest, nil
@@ -383,11 +385,13 @@ func getLocalPath(ctx context.Context, digest string) (*api.ServerConfig, error)
 			fmt.Println("error unmarshalling response data")
 			return nil, err
 		}
+
+		return &respData, nil
 	}
 
 	fmt.Println("!!!!!!!!!!")
 	fmt.Println(respData)
-	return &respData, nil
+	return nil, ErrBlobExists
 }
 
 func createBlobLocal(path string, dest string) error {

+ 3 - 13
server/routes.go

@@ -782,20 +782,10 @@ func (s *Server) CreateBlobHandler(c *gin.Context) {
 		c.Status(http.StatusOK)
 		return
 	}
-	fmt.Println("HEIAHOEIHFOAHAEFHAO")
-	fmt.Println(c.GetHeader("X-Redirect-Create"))
-	if c.GetHeader("X-Redirect-Create") == "1" {
-		response := api.ServerConfig{ModelDir: path}
-		fmt.Println("Hit redirect")
-		resp, err := json.Marshal(response)
-		fmt.Println("marshalled response")
-		if err != nil {
-			c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
-			return
-		}
 
-		c.Header("loc", string(resp))
-		fmt.Println("!!!!!!!!!", string(resp))
+	if c.GetHeader("X-Redirect-Create") == "1" {
+		c.Header("Location", path)
+		fmt.Println("!!!!!!!!!", string(path))
 		c.Status(http.StatusTemporaryRedirect)
 		return
 	}