Live demo at Spencer's OneDrive Index.
README.md
if found in current folder. Rendered with github-markdown-css..txt
. DEMO..md
, .mdown
, .markdown
. DEMO..png
, .jpg
, and .gif
. DEMO..js
, .py
, .c
, .json
.... DEMO..mp3
, .aac
, .wav
, .oga
. DEMO..mp4
, .flv
, .webm
, .m3u8
. DEMO.?proxied
- Downloads the file through CloudFlare Workers if (1) proxyDownload
is true in config/default.js
and (2) parameter is present in url.?raw
- Return direct raw file instead of rich rendered preview if parameter is present.?proxied&raw
and ?raw&proxied
are both valid.Yes, this means you can use this project as an image storage service or for serving static files, for example:
https://storage.spencerwoo.com/%F0%9F%A5%9F%20Some%20test%20files/nyancat.gif?raw
See the new features section at the original onedrive-index-cloudflare-worker project page for reference, although I cannot guarantee that all features are usable.
Very, very long, tedious, step by step guide warning! Online token generation tool taken from the generous: https://heymind.github.io/tools/microsoft-graph-api-auth. We will be using this in the following steps.
Create a new blade app here Microsoft Azure App registrations (OneDrive normal version) or Microsoft Azure.cn App registrations (OneDrive 世纪互联版本):
New registration
.Name
for your blade app, my-onedrive-cf-index
for example.Supported account types
to Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)
. OneDrive 世纪互联用户设置为:任何组织目录(任何 Azure AD 目录 - 多租户)中的帐户
.Redirect URI (optional)
to Web
(the multiselect dropdown) and https://heymind.github.io/tools/microsoft-graph-api-auth
(the URL).Register
.Get your Application (client) ID - client_id
at Overview
panel.
Open Certificates & secrets
panel, click New client secret
and create a new secret called client_secret
, set Expires
to Never
, click Add
, and copy the Value
of the client_secret
(You only have this one chance to copy it.).
Open API permissions
panel, select Microsoft Graph
, select Delegated permissions
, search for offline_access, Files.Read, Files.Read.All
, select all three of them and click Add permissions
.
You should have these permissions ready:
Get your refresh_token
:
Open https://heymind.github.io/tools/microsoft-graph-api-auth.
At 4. Authorize for code
, input our client_id
, and hit AUTHORIZE
.
Log into your Microsoft account and authorize our app, if you are returned with a code like what is shown below, then your authorization process is successful:
Hit OK
, and proceed on to the next stage.
At 5. Exchange Access Token
, the Code
should already be inputted into the correct place for us, we only need to input our client_secret
:
Click GET TOKEN
. If there is an error like error: "invalid_request"
, then please resolve to the solution suggested in the pinned issue #13. Otherwise, collect your access_token
and if you need, use the final Refresh Token
to collect your refresh_token
as well.
Finally, create a dedicated folder for your public files inside OneDrive, for instance: /Public
. Please don't share your root folder directly!
After all this hassle, you should have successfully acquired the following tokens and secrets:
refresh_token
client_id
client_secret
redirect_uri
: Defaults to https://heymind.github.io/tools/microsoft-graph-api-auth
.base
: Defaults to /Public
.Yes, I know it's a long and tedious procedure, but it's Microsoft, we can understand. 🤷🏼♂️
Fork or directly clone this repository. Install dependencies, you'll need Node.js, npm
and wrangler
.
We strongly recommend you install npm with a Node version manager like n or nvm, which will allow wrangler to install configuration data in a global node_modules directory in your user's home directory, without requiring that you run as root.
# Install cloudflare workers official packing and publishing tool
npm i @cloudflare/wrangler -g
# Install dependencies with npm
npm install
# Login to Cloudflare with wrangler
wrangler login
# Verify wrangler status with this command
wrangler whoami
Login to your CloudFlare account at https://dash.cloudflare.com/login, select your domain, and scroll down a bit. You'll see your account_id
and zone_id
there (on the right sidebar). Also create a DRAFT worker at Workers
-> Manage Workers
-> Create a Worker
with a cool name.
Modify wrangler.toml
:
name
: The draft worker's name, your worker will be published at <name>.<worker_subdomain>.workers.dev
.account_id
: Your Cloudflare Account ID.zone_id
: Your Cloudflare Zone ID.Create Cloudflare Workers KV bucket named BUCKET
:
# Create KV bucket
wrangler kv:namespace create "BUCKET"
# ... or, create KV bucket with preview functions enabled
wrangler kv:namespace create "BUCKET" --preview
Modify kv_namespaces
inside wrangler.toml
:
kv_namespaces
: Your Cloudflare KV namespace, you should substitute the id
and preview_id
values accordingly. If you don't need preview functions, you
can remove the preview_id
field.
Modify src/config/default.js
:
client_id
: Your client_id
from above.base
: Your base
path from above.For Chinese 21Vianet OneDrive users. OneDrive 世纪互联用户:将 useCnEndpoints
设置(修改)为 true
。
Add secrets to Cloudflare Workers environment variables with wrangler
:
# Add your refresh_token and client_secret to Cloudflare
wrangler secret put REFRESH_TOKEN
# ... enter your refresh_token from above here
wrangler secret put CLIENT_SECRET
# ... enter your client_secret from above here
You can preview the worker with wrangler
:
wrangler preview
After making sure everything is ok, you can publish your worker with:
wrangler publish
You can also create a GitHub Actions for auto publishing your worker on push
. See main.yml.
For custom domains, refer to How to Setup Cloudflare Workers on a Custom Domain.
intro
on the default landing page here: src/folderView.js. Write HTML directly.🏵 onedrive-cf-index ©Spencer Woo. Released under the MIT License.
Authored and maintained by Spencer Woo.
@Portfolio · @Blog · @GitHub