Edits history of script submission #18755 for ' Delete a file (replicate)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Replicate = {
      token: string;
    };
    /**
     * Delete a file
     * Delete a file. Once a file has been deleted, subsequent requests to the file resource return 404 Not found.
    
    Example cURL request:
    
    ```console
    curl -X DELETE \
      -H "Authorization: Token $REPLICATE_API_TOKEN" \
      https://api.replicate.com/v1/files/cneqzikepnug6xezperrr4z55o
    ```
    
     */
    export async function main(auth: Replicate, file_id: string) {
      const url = new URL(`https://api.replicate.com/v1/files/${file_id}`);
    
      const response = await fetch(url, {
        method: "DELETE",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 235 days ago