基于 gh-proxy + Jsdelivr+ cnpmjs + cloudflare workers 的 GitHub Serverless API 工具。

Overview

better-github-api

Better, Eazy, Access Anywhere

介绍

基于 gh-proxy + Jsdelivr + cnpmjs + cloudflare workers 的 GitHub Serverless API 工具。

cdn.js:仅含 gh-proxy 中的CDN功能,URL后加上GitHub各种资源(源码、Release文件等)的下载链接跳转为对应CDN加速的链接。

api.js:本项目的核心,提供API服务,部署时只用修改最开始的几个变量参数。

问题

  • GitHub资源下载龟速,你我都有办法,但是用户没有,而分发存储到其他地方也可能会增加开支和麻烦。
  • GitHub的API没有办法直接获得 Release 的某个附件,如提供过滤选项在众多Assets中筛选想要的附件,获取最新版本的某个附件只能通过解析API进一步操作,而实际应提供一个固定、简短的API。
  • Jsdelivr很好用,可结合GitHub Actions自动搬运资源,但是有~20MB/文件限制。

优势

  • 使用 Jsdelivr 等CDN加速资源下载,Release文件加速无大小限制;
  • 提供简明的API,可作为程序分发的固定下载链接;
  • 开销低,每个账号CloudFlare Workers 免费请求额度为 ~1k次/小时 ~100k次/天,5$付费版 ~10m次/天,且可开多个账号。

如需用自己的域名,应使用CloudFlare的DNS服务(maybe可用CNAME跳转Worker的域名)

路线

  • repo
  • get
  • bucket
  • submit
  • list
  • submit可视化提交界面

使用

如果有配置好的API服务可以直接使用,API参考这里,这里给出可用的域名,请尽量自己搭建减少这里的压力,毕竟是免费的,也可提交你的域名

下面是使用举例:

含义 URL
获取advancedfx仓库的最新版本号 https://api.upup.cool/repo/advancedfx/advancedfx/version
获取advancedfx仓库的最新版本包含hlae字符串的zip压缩包 https://api.upup.cool/repo/advancedfx/advancedfx/&hlae&&&.zip
获取advancedfx仓库的最新版本号v2.115.0的HLAE_Setup.exe安装器 https://api.upup.cool/repo/advancedfx/advancedfx/v2.115.0/&HLAE_Setup.exe
获取本仓库最新源代码 https://api.upup.cool/repo/One-Studio/better-github-api/source
获取本仓库最新简化信息 https://api.upup.cool/repo/One-Studio/better-github-api/info
获取...上述zip压缩包,使用KV键值对预先存好的信息 https://api.upup.cool/get/hlae
获取advancedfx仓库的最新版本号 https://api.upup.cool/get/hlae/version

部署

登录 Cloudflare Workers 注册,登陆,选择Workers,创建Worker。下面的服务可自由选择。

CDN服务

  1. 复制项目文件中cdn.js的内容到左侧代码框;
  2. 修改 ASSET_URL, Config, PREFIX
  3. 保存并部署;
  4. (可选)修改Worker的域名/路由。

API服务

  1. 复制项目文件中api.js的内容到左侧代码框,保存并部署
  2. 修改 ASSET_URL, Config, PREFI;
  3. 修改 HOME_PAGE,请求不加参数时跳转到主页;
  4. 保存并部署;
  5. 返回Workers界面,点击KV设置命名空间,添加两个命名空间:KVBUCKET(可修改),回到Worker的设置页绑定命名空间,注意变量名称必须是KVBUCKET
  6. 提交KV键值对:给刚才绑定KV变量名的命名空间添加键值对(仓库简称-值)以使用get方法,参照这里
  7. (可选)修改Worker的域名/路由。

配置参数说明:

ASSET_URL 修改为Worker的域名,如用自定义域名也要改成对应的。

↓一般不用改

Config clone是否使用cnpm,项目文件是否使用jsDeliver的开关,1开,0关。

PREFIX 前缀,,默认(根路径情况为"/"),如果自定义路由为example.com/gh/*,请将PREFIX改为 '/gh/',注意,少一个杠都会错!

域名修改说明:

如果有自己的域名,可以给CDN和API服务分配分配到两个子域名中。使用CloudFlare做域名的DNS服务器之后,按下表设置DNS:

类型 名称 内容
A api 8.8.8.8
A cdn 8.8.8.8

然后在域名设置页找到Workers,添加路由,路由格式:

api.upup.cool/*
cdn.upup.cool/*

API设计

KV(Key-Value)键值对:CloudFlare提供了免费1GB的键值对存储功能,可以设置多个命名空间,Workers可以读写这些键值实现一些功能

一级API

参数 含义
/repo 获取GitHub仓库信息
/get 利用KV中已有的键值对快速获取GitHub仓库信息
/bucket 与get类似,使用KV缓存的键值信息简化参数复杂度,加快响应
/submit 向KV提交键值对
/list 列出KV键值对

二级API

/repo

API 含义
/仓库主/仓库名 获取该仓库的最新版本的唯一附件
/仓库主/仓库名/version 获取该仓库的最新版本的版本号
/仓库主/仓库名/source 获取该仓库的最新版本的源代码下载地址
/仓库主/仓库名/info 获取该仓库的最新版本的信息,如版本号和附件
/仓库主/仓库名/过滤器 获取该仓库的最新版本的附件,同时过滤附件名得到唯一附件
/仓库主/仓库名/版本 获取该仓库的给定版本的唯一附件
/仓库主/仓库名/版本/version 获取该仓库的给定版本的唯一附件
/仓库主/仓库名/版本/source 获取该仓库的给定版本的源代码下载地址
/仓库主/仓库名/版本/info 获取该仓库的给定版本的信息,如版本号和附件
/仓库主/仓库名/版本/过滤器 获取该仓库的给定版本的附件,同时过滤附件名得到唯一附件
仓库信息 类型 示例
仓库主 string One-Studio
仓库名 string better-github-api
版本 含义 示例
latest 最新版本 latest
其他 指定的其他版本 v2.116.0
info成员 类型 含义
version string 版本号
source string 源代码URL
assets asset array 附件
log string 更新日志
asset成员 类型 含义
name string 附件名
size int 附件大小
browser_download_url string 附件下载链接 (TODO 原始 or 加速后?)

filter用&分隔的过滤器各个部分,必须&开头,格式为 &include&exclude&start&end ,可用格式的示例如下:

  • &hlae&&&.zip
  • &HLAE_Setup.exe
  • &HLAE_Setup.exe&&&
  • &hlae&.exe
  • &hlae&.exe&&

右侧连通的空白部分&可省去。

过滤器部分 含义
include 包含字符串 hlae
exclude 排除字符串
start 开头字符串
end 结尾字符串 .zip

/get

仓库简称后的API与repo一致,区别在使用KV存储的信息(仓库主、仓库名、filter等)简化API。

API 含义
/get/仓库简称 获取该仓库的最新版本的唯一附件
/get/仓库简称/version 获取该仓库的最新版本的版本号
/get/仓库简称/source 获取该仓库的最新版本的源代码下载地址
/get/仓库简称/info 获取该仓库的最新版本的信息,如版本号和附件
/get/仓库简称/过滤器 获取该仓库的最新版本的附件,同时过滤附件名得到唯一附件
/get/仓库简称/版本 获取该仓库的给定版本的唯一附件
/get/仓库简称/版本/version 获取该仓库的给定版本的唯一附件
/get/仓库简称/版本/source 获取该仓库的给定版本的源代码下载地址
/get/仓库简称/版本/info 获取该仓库的给定版本的信息,如版本号和附件
/get/仓库简称/版本/过滤器 获取该仓库的给定版本的附件,同时过滤附件名得到唯一附件

至于KV里如何存简称-全称的对应关系:

类型 含义
repo string 仓库主/仓库名 advancedfx/advancedfx
filter string 附件名过滤器 &hlae&&&.zip
info object KV键值对信息(多语言) {"zh_CN": "hlae的zip安装包", "zh_TW": "hlae的zip安裝器"}

举例:键为 hlae,值为:

{
	"repo": "advancedfx/advancedfx",
	"filter": "&hlae&&&.zip",
	"info": {
		"zh_CN": "hlae的zip安装包",
		"zh_TW": "hlae的zip安裝包"
	}
}

之后使用URL如https://api.upup.cool/get/hlae即可直接下载hlae的最新zip安装包,同时包含CDN服务,避免了很多访问速度的问题。

/bucket (未完成)

API示例 含义
/bucket 获取所有bucket信息
/bucket/hlae 获取hlae最新安装包
/bucket/hlae/version
/bucket/ffmpeg/win/
/bucket/ffmpeg/win/
/get/hlae

/submit(未完成)

You might also like...

Remix + Cloudflare Workers + Wrangler2 + Tailwind + ESLint + Prettier + Vitest + Playwright

Welcome to Remix! Remix Docs Development You will be running two processes during development: The Miniflare server (miniflare is a local environment

Dec 19, 2022

Server-side rendering blog runs on Cloudflare workers

Serverside rendered blog I have tried something completely against to current web trends. What are these? I am using the React as backend framework wi

Jun 24, 2022

A collection of useful tools for building web apps on Cloudflare Workers.

Keywork is a batteries-included, magic-free, library for building web apps on Cloudflare Workers. Features 💪 Written in TypeScript 📚 Modules Support

Dec 22, 2022

Abusing Cloudflare Workers to establish persistence and exfiltrate sensitive data at the edge.

Abusing Cloudflare Workers This repository contains companion code for the blog post MITM at the Edge: Abusing Cloudflare Workers. malicious-worker/ c

Sep 16, 2022

A starter template for Remix + Cloudflare Workers + DO + KV + Turborepo

Remix + Cloudflare Workers starter with Turborepo 🚀 Starter to get going with Remix and Cloudflare Workers. This template is based on the starter cre

Jan 2, 2023

A Cloudflare Workers service that fetches and renders Notion pages as HTML, Markdown, or JSON.

notion-fetch A Cloudflare Workers service that fetches and renders Notion pages as HTML, Markdown, or JSON. Powered by Durable Objects and R2. Usage P

Jan 6, 2023

A flexible gateway for running ML inference jobs through cloud providers or your own GPU. Powered by Replicate and Cloudflare Workers.

Cogflare (Working title) Cogflare is a Cloudflare Workers application that aims to simplify running distributed ML inference jobs through a central AP

Dec 12, 2022

Firebase/Admin Auth Javascript Library for Cloudflare Workers

Flarebase Auth Firebase/Admin Auth Javascript Library for Cloudflare Workers Supported operations: createSessionCookie() verifySessionCookie() signInW

Jan 1, 2023

A zero-dependency, strongly-typed web framework for Bun, Node and Cloudflare workers

nbit A simple, declarative, type-safe way to build web services and REST APIs for Bun, Node and Cloudflare Workers. Examples See some quick examples b

Sep 16, 2022
Releases(V1.3)
Owner
One Studio
All in One
One Studio
Low cost, low effort P2P WebRTC serverless signalling using Cloudflare Workers

P2PCF P2PCF enables free (or cheap) serverless WebRTC signalling using a Cloudflare worker and a Cloudflare R2 bucket. The API is inspired by P2PT, bu

Greg Fodor 560 Jan 8, 2023
Google-Drive-Directory-Index | Combining the power of Cloudflare Workers and Google Drive API will allow you to index your Google Drive files on the browser.

?? Google-Drive-Directory-Index Combining the power of Cloudflare Workers and Google Drive will allow you to index your Google Drive files on the brow

Aicirou 127 Jan 2, 2023
Lightweight universal Cloudflare API client library for Node.js, Browser, and CF Workers

Cloudflare API Client Lightweight universal HTTP client for Cloudflare API based on Fetch API that works in Node.js, browser, and CF Workers environme

Kriasoft 15 Nov 13, 2022
Dead-simple CORS handling for any itty-router API (test with Cloudflare Workers, but works anywhere)!

Simple CORS-handling for any itty-router API. Designed on Cloudflare Workers, but works anywhere. Features Tiny. Currently ~600 bytes, with zero-depen

Kevin R. Whitley 6 Dec 16, 2022
proxy 🦄 yxorp is your Web Proxy as a Service (SAAS) Multi-tenant, Multi-Threaded, with Cache & Article Spinner

proxy ?? yxorp is your Web Proxy as a Service (SAAS) Multi-tenant, Multi-Threaded, with Cache & Article Spinner. Batteries are included, Content Spinning and Caching Engine, all housed within a stunning web GUI. A unique high-performance, plug-and-play, multi-threaded website mirror and article spinner

4D/ҵ.com Dashboards 13 Dec 30, 2022
Proxy but misspelled -- closed proxy for the internet

pyrox Proxy that runs on Cloudflare Workers. Setup Install wrangler2. npm install wrangler. Generate a public Ed25519 key, exported under SPKI mode wi

bots.gg 10 Sep 9, 2022
A URL shortener that runs on Cloudflare Workers

ITP Works A URL shortener that runs on Cloudflare Workers. It stores the rules in Cloudflare KV storage and sends a 301 redirect when a matched pathna

Yifei Gao 3 Mar 4, 2022
Starting template for building a Remix site with CloudFlare Workers (ES Modules Syntax)

Starting template for building a Remix site with CloudFlare Workers (ES Modules Syntax)

null 12 May 20, 2022
Remix + Cloudflare Workers + DO + Turborepo

Remix + Cloudflare Workers + DO + Turborepo A starter to get you up and going with Remix on Cloudflare with all the latest and greatest. What's inside

Jacob Ebey 38 Dec 12, 2022