{"id":22204911,"url":"https://github.com/masfana/github-image-bucket-api","last_synced_at":"2025-09-07T16:43:37.908Z","repository":{"id":264622685,"uuid":"893884429","full_name":"MasFana/Github-Image-Bucket-API","owner":"MasFana","description":"Simple Image Bucket API using Github Repo and HTML CSS as The UI","archived":false,"fork":false,"pushed_at":"2024-11-28T06:49:20.000Z","size":118,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T01:21:55.602Z","etag":null,"topics":["api","bucket","github","image","image-api","nodejs"],"latest_commit_sha":null,"homepage":"","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MasFana.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-25T11:30:21.000Z","updated_at":"2025-02-07T14:42:17.000Z","dependencies_parsed_at":"2024-11-25T12:38:52.666Z","dependency_job_id":null,"html_url":"https://github.com/MasFana/Github-Image-Bucket-API","commit_stats":null,"previous_names":["masfana/github-image-bucket-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MasFana/Github-Image-Bucket-API","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MasFana%2FGithub-Image-Bucket-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MasFana%2FGithub-Image-Bucket-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MasFana%2FGithub-Image-Bucket-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MasFana%2FGithub-Image-Bucket-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MasFana","download_url":"https://codeload.github.com/MasFana/Github-Image-Bucket-API/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MasFana%2FGithub-Image-Bucket-API/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272885662,"owners_count":25009672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","bucket","github","image","image-api","nodejs"],"created_at":"2024-12-02T17:20:49.677Z","updated_at":"2025-08-30T18:14:31.447Z","avatar_url":"https://github.com/MasFana.png","language":"CSS","readme":"\n# Github Image Bucket API\n\n![UI](UI.png)\n\nThis project is a proof of concept for using a GitHub repository as an image hosting service. The API allows users to upload, list, and delete image files from the repository, providing an easy interface to manage files hosted on GitHub.\n\n## Table of Contents\n-   [Installation](#installation)\n-   [Environment Variables](#environment-variables)\n-   [API Endpoints](#api-endpoints)\n    -   [POST /upload](#post-upload)\n    -   [GET /files](#get-files)\n    -   [DELETE /delete](#delete)\n-   [Utility Functions](#utility-functions)\n-   [Running the Server](#running-the-server)\n\n----------\n\n## Installation\n\nTo set up and run this project, you need Node.js and npm installed on your system.\n\n1.  Clone the repository:\n    \n    ```bash\n    git clone https://github.com/MasFana/Github-Image-Bucket-API\n    cd Github-Image-Bucket-API\n    \n    ```\n    \n2.  Install dependencies:\n    \n    ```bash\n    npm install\n    \n    ```\n    \n3.  Set up environment variables by creating a `.env` file in the root directory with the following values:\n    \n    ```env\n    GITHUB_TOKEN=\u003cyour_github_token\u003e\n    GITHUB_REPO=\u003cyour_github_repo\u003e\n    GITHUB_BRANCH=\u003cyour_github_branch\u003e\n    \n    ```\n    \n4.  Start the server:\n    \n    ```bash\n    npm start\n    \n    ```\n    \n\nThe server will run on `http://localhost:3000`.\n\n----------\n\n## Environment Variables\n\nThe API requires the following environment variables to be set:\n\n-   `GITHUB_TOKEN`: GitHub Personal Access Token for authentication.\n-   `GITHUB_REPO`: GitHub repository name in the format `owner/repository`.\n-   `GITHUB_BRANCH`: GitHub branch name where files will be uploaded.\n\n----------\n\n## API Endpoints\n\n### POST /upload\n\nUploads a file to the configured GitHub repository.\n\n#### Request\n\n-   **Content-Type**: `multipart/form-data`\n-   **Body**: A form-data containing a file under the key `file`.\n\n#### Response\n\n-   **200 OK**: If the file is successfully uploaded, returns the public URL of the uploaded file.\n    \n    ```json\n    {\n      \"publicUrl\": \"https://raw.githubusercontent.com/\u003crepo\u003e/\u003cbranch\u003e/uploads/\u003cfile_name\u003e\"\n    }\n    \n    ```\n    \n-   **500 Internal Server Error**: If the upload fails, an error message is returned.\n    \n    ```json\n    {\n      \"error\": \"Failed to upload the file\"\n    }\n    \n    ```\n    \n\n----------\n\n### GET /files\n\nRetrieves a list of all files uploaded to the GitHub repository.\n\n#### Request\n\n-   No parameters are required.\n\n#### Response\n\n-   **200 OK**: Returns a list of file names with their corresponding public URLs.\n    \n    ```json\n    [\n      {\n        \"name\": \"\u003cfile_name\u003e\",\n        \"url\": \"https://raw.githubusercontent.com/\u003crepo\u003e/\u003cbranch\u003e/uploads/\u003cfile_name\u003e\"\n      },\n      ...\n    ]\n    \n    ```\n    \n-   **500 Internal Server Error**: If there is an issue retrieving the file list, an error message is returned.\n    \n    ```json\n    {\n      \"error\": \"Failed to retrieve files\"\n    }\n    \n    ```\n    \n\n----------\n\n### DELETE /delete\n\nDeletes a file from the GitHub repository.\n\n#### Request\n\n-   **Content-Type**: `application/json`\n    \n-   **Body**: JSON object with the file name to be deleted.\n    \n    ```json\n    {\n      \"fileName\": \"\u003cfile_name\u003e\"\n    }\n    \n    ```\n    \n\n#### Response\n\n-   **200 OK**: If the file is successfully deleted, returns a success message.\n    \n    ```json\n    {\n      \"message\": \"File \\\"\u003cfile_name\u003e\\\" deleted successfully\"\n    }\n    \n    ```\n    \n-   **400 Bad Request**: If the file name is not provided in the request body.\n    \n    ```json\n    {\n      \"error\": \"File name is required\"\n    }\n    \n    ```\n    \n-   **500 Internal Server Error**: If there is an error deleting the file, an error message is returned.\n    \n    ```json\n    {\n      \"error\": \"Failed to delete the file\"\n    }\n    \n    ```\n    \n\n----------\n\n## Utility Functions\n\n-   **readFileAsBase64(filePath)**: Reads a file from the specified `filePath` and returns its content encoded as Base64.\n-   **deleteLocalFile(filePath)**: Deletes a local file from the given `filePath`.\n-   **getGithubFileSha(fileName)**: Retrieves the SHA hash of a file stored in the GitHub repository for deletion.\n-   **uploadFileToGithub(file, content)**: Uploads a file to the GitHub repository with its Base64 content.\n-   **deleteFileFromGithub(fileName, sha)**: Deletes a file from the GitHub repository using its SHA hash.\n\n----------\n\n## Running the Server\n\n1.  Install all required dependencies:\n    \n    ```bash\n    npm install\n    \n    ```\n    \n2.  Start the Express server:\n    \n    ```bash\n    npm start\n    \n    ```\n    \n    The API will be available at `http://localhost:3000`.\n    \n\n----------\n\n## Notes\n\n-   Ensure that your GitHub repository is set up to accept file uploads and has the correct permissions for your GitHub token.\n-   This API assumes that the uploaded files will be stored in the `uploads/` directory in the GitHub repository.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasfana%2Fgithub-image-bucket-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmasfana%2Fgithub-image-bucket-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasfana%2Fgithub-image-bucket-api/lists"}