github_s3

package module
v0.0.0-...-0c78b4d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 11 Imported by: 1

README

GitHub as a file server

Abuse GitHub unpublicized attachment API to serve a file.

Especially useful for hosting image files that can be referenced in markdown files.

Usage

  1. Install
    go install github.com/barn2plugins/github-s3/cmd/github-s3@latest
    
  2. Login to your GitHub account, and obtain cookie named user_session from GitHub web browser session.
  3. Run
    export GITHUB_SESSION=<github-user-session>   
    github-s3 [-repo owner/repo] [-pat ghp_1234567890abcdefghijklmnopqrstuvwyz0] <path-to-file>
    
Parameters

The command supports two parameters:

  • -repo (optional): This parameter specifies the repository where you want to upload your assets, in the form <owner>/<respository> (if you skip this parameter, the cli/cli repository will be used)
  • -pat (optional): This parameter provides the Personal Access Token of the user uploading the assets. This parameter is only required if the repository specified with the -repo parameter is private. The Personal Access Token must be created with the repo and the write:discussion permissions

If you don't want to obtain the cookie manually, you can use github-s3-auto to automatically find the cookie from your web browser session.

go install github.com/barn2plugins/github-s3/cmd/github-s3-auto@latest

github-s3-auto [-repo owner/repo] [-pat ghp_1234567890abcdefghijklmnopqrstuvwyz0] <path-to-file>

Disclaimer

Please note that this project relies on an unpublicized API of GitHub, and its usage may be subject to changes in GitHub's policies or API. Use it responsibly and ensure compliance with GitHub's terms of service.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(sessionGetter func() string)

Types

type GitHub

type GitHub struct {
	// contains filtered or unexported fields
}

func New

func New(userSession string, repo string, pat string) *GitHub

func (*GitHub) Upload

func (g *GitHub) Upload(name string, size int, r io.Reader) (UploadResult, error)

func (*GitHub) UploadFromPath

func (g *GitHub) UploadFromPath(path string) (UploadResult, error)

type UploadResult

type UploadResult struct {
	// The URL of the uploaded files.
	GithubLink string
	// If the file is an image or video, the direct AWS link to the file (After redirected from the GitHub link).
	// For other type of files, this field is empty.
	AwsLink string
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL