This project uses CloudFlare Workers to help you deploy and share your OneDrive files for free. This project is largely derived from: onedrive-index-cloudflare-worker, tribute.
-
Visit this URL to create a new Blade app: Microsoft Azure App registrations (normal version of OneDrive) or Microsoft Azure.cn App registrations (OneDrive 21Vianet version) :
- Log in with your Microsoft account, select
New registration
; - Set the name of the Blade app at
Name
, such asmy-onedrive-cf-index
; - Set
Supported account types
toAccounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)
. OneDrive 21Vianet user set to:Account in any organizational directory (any Azure AD directory - multi-tenant)
; - Set
Redirect URI (optional)
toWeb
(drop-down option box) andhttp://localhost
(URL address); - Click
Register
.
- Log in with your Microsoft account, select
-
Get your Application (client) ID -
client_id
in theOverview
panel: -
Open the
Certificates & secrets
panel, clickNew client secret
, create a new Client secret calledclient_secret
, and setExpires
toNever
. ClickAdd
and copyclient_secret
theValue
and save it (only one chance): -
Open the
API permissions
panel, selectMicrosoft Graph
, selectDelegated permissions
, and search for the three permissionsoffline_access, Files.Read, Files.Read.All
, select these three permissions, and ClickAdd permissions
:You should successfully enable these three permissions:
-
Obtain
refresh_token
, and execute the following command on the local machine (need Node.js and npm environment, please refer to Preparation for installation and recommended configuration):npx @beetcb/ms-graph-cli
Choose the appropriate option according to your own situation, and enter a series of token token configurations we obtained above, among which
redirect_url
can be directly set tohttp://localhost
. For the specific usage of command line tools, please refer to: beetcb/ms-graph-cli. -
Finally, create a public shared folder in our OneDrive, such as
/Public
. It is recommended not to share the root directory directly!
Finally, after all this tossing, we should have successfully obtained the following credentials:
refresh_token
client_id
client_secret
redirect_uri
base
: defaults to/Public
.
Yes, I know it's troublesome, but this is Microsoft, please understand. ๐คท๐ผโโ๏ธ
Fork and then clone or directly clone this warehouse, and install dependencies Node.js, npm
and wrangler
.
_It is strongly recommended that you use Node version manager such as n or nvm to install Node.js and npm
, so that the wrangler
we installed globally can install and save configuration files in our user directory, and we will not encounter strange permission problems. _
# Install CloudFlare Workers official compilation and deployment tool
npm install -g wrangler
# install dependencies using npm
npm install
# Login to CloudFlare account with wrangler
wrangler login
# Use this command to check your login status
wrangler whoami
Open https://dash.cloudflare.com/login, log in to CloudFlare, create a worker at Workers
-> Manage Workers
-> Create a Worker
, and then look on the right side for your Accound ID.
Modify our wrangler.toml
:
name
: is the name of the worker we just created, and our Worker will be published under this domain name by default:<name>.<worker_subdomain>.workers.dev
;account_id
: our Cloudflare Account ID;
Create a Cloudflare Workers KV bucket called BUCKET
:
# create KV bucket
wrangler kv:namespace create "BUCKET"
# ... Alternatively, create a KV bucket that includes preview functionality
wrangler kv:namespace create "BUCKET" --preview
The preview function is only used for local testing, and has nothing to do with the image preview function on the page.
Modify kv_namespaces
in wrangler.toml
:
kv_namespaces
: our Cloudflare KV namespace, just replaceid
and/orpreview_id
. _If you don't need the preview function, just removepreview_id
. _
Modify src/config/default.js
:
client_id
: the OneDriveclient_id
just obtained;base
: the previously createdbase
directory;- If you deploy the regular international version of OneDrive, then ignore the following steps;
- If you are deploying the China version of OneDrive operated by 21Vianet:
- Modify
accountType
undertype
to1
; - keep
driveType
unchanged;
- Modify
- If you are deploying a SharePoint service:
- leave
accountType
unchanged; - Modify
type
underdriveType
to1
; - and modify
hostName
andsitePath
according to your SharePoint service.
- leave
Use wrangler
to add Cloudflare Workers environment variables (We can lock a specific folder (directory) and require authentication to access it. We can write the directories we want to make private folders into the ENABLE_PATHS
list in the src/auth/config.js
file. We can also customize the user name NAME
and password used for authentication, where the authentication password is saved in the AUTH_PASSWORD
environment variable, which needs to be set using wrangler):
# Add our refresh_token and client_secret
wrangler secret put REFRESH_TOKEN
# ... and paste our refresh_token here
wrangler secret put CLIENT_SECRET
# ... and paste our client_secret here
wrangler secret put AUTH_PASSWORD
# ... enter the authentication password we set here
Add Required Packages
npm install font-awesome-filetypes marked
We can then preview the deployment using wrangler
:
wrangler dev
If all goes well, we can publish the Cloudflare Worker with the following command:
wrangler publish
We can also create a GitHub Actions to automatically publish a new Worker every time push
to the GitHub repository, for details, refer to: main.yml.
If you want to deploy Cloudflare Worker under your own domain name, please refer to: How to Setup Cloudflare Workers on a Custom Domain.
- We should change the default "landing page", directly modify the HTML of
intro
in src/folderView.js; - We also should change the header of the page, just modify src/render/htmlWrapper.js directly;
- The style CSS file is located at themes/spencer.css, you can customize this file according to your own needs, and you also need to update src/render/htmlWrapper.js commit HASH in the file;
- We can also customize Markdown rendering CSS style, PrismJS code highlighting style, etc.