Ratodo

夜半观星

我的花园到处是星星的碎片
telegram
github
email
nintendo switch

Build TCShare using Tencent Cloud Function SCF.

Preface#

Previously, the resource sharing on the website was based on OneDrive storage using oneindex. However, the link speed of OneDrive international version in China is really terrible. The speed of the Century Internet version is fast, but most of them can only be used for enterprise versions, which is not within the scope of consideration this time.

Since TCShare upgraded to version 3.0, it has also added support for HeCaiyun, OneDrive, and OneDrive Century Internet version. In addition to the already supported Tianyi Cloud Drive, there are enough cloud drive options to choose from.

Since I am still a mobile user, I am using the mobile HeCaiyun, which has enough space to share some things in daily life. The most important thing is that there is no speed limit and the connection speed is very fast. It may be one of the few conscience products of China Mobile.

Setup Tutorial#

The setup methods mainly include server setup and Tencent Cloud Function (SCF) setup. Regarding server setup, it is very simple. After setting up the files, just run "composer install" to complete the installation. Below, I will mainly explain the setup method for Tencent Cloud Function (SCF).

Why choose Tencent Cloud Function? Tencent Cloud Function has a fixed amount of free quota every month, plus the first year's monthly free traffic of API Gateway. It is completely sufficient for personal use.

Pic1

Pic2

However, this service is not completely free. Please pay attention to the official announcements and remaining free quota when using it.

1. Download the source code to your local machine and install dependencies#

Github

The original author stopped updating and deleted the code for some reasons, and only kept the releases. You can check my fork page for installation instructions.

Github

After downloading the source code from Github, install PHP and Composer on your local machine. You can find the relevant installation packages for PHP and Composer here. Alternatively, you can complete the Composer dependency installation on your own server and then download the folder with the installed dependencies.

First, unzip PHP, then open composer_setup.exe and manually select the php.exe that was just extracted to install it.

After the installation is complete, use the cmd command to navigate to the folder where the source code is located and enter the command:

composer install

2. Create SCF#

Go to Tencent Cloud Function and create a new function in the left-side function service. You can choose the region at the top, select PHP 7.2 as the runtime environment, and choose the blank function mode.

Pic3

The execution method is index.main_handler, and the submission method is to upload the local folder. Select the folder that was just prepared and submit it.

Open the advanced settings, enter the environment variables, and set them as follows. It is recommended to carefully read the documentation on Github for more detailed instructions:

## Tianyi Cloud and OneDrive section

# XS is the prefix
# | - KEY is the configuration type, optional KEY, APP, SEC
# | | - - ct is the key ID (similar to config.php)
# | | - | - something is the configuration name
# | | - | - | - - - - value is on the right side of the equal sign
# XS_KEY_ct_something=value

    # Tianyi Cloud configuration
    XS_KEY_ct=ctyun   # Required, value is ctyun
    XS_KEY_ct_FD=     # Application folder name
    XS_KEY_ct_AK=     # AK
    XS_KEY_ct_SK=     # SK
    # Onedrive configuration
    XS_KEY_od=onedrive
    # Century Internet configuration
    XS_KEY_od=onedriveCN

# The value after APP can be any value, generally 123456 and so on
#          ↓
    XS_APP_1=/              # Mount path
    XS_APP_1_NAME=TCShare   # Cloud drive name
    XS_APP_1_THEME=mdui     # Interface theme
    XS_APP_1_BASE=/         # Path within the cloud drive
    XS_APP_1_KEY=ct         # Corresponding to the ID of the Key above

## HeCaiyun section

XS_KEY_cm=caiyun
XS_KEY_cm_TOKEN='{"cyToken":"******|*|RCS|******|******","encryPhone":"******"}'
XS_APP_<id>_NAME="TCShare HeCaiyun"
XS_APP_<id>_THEME=mdui
XS_APP_<id>_BASE=/
XS_APP_<id>_KEY=cm
XS_APP_<id>=/caiyun

The left side of the equal sign is the key to be filled in, and the right side is the corresponding value. Please note that if you are using HeCaiyun, do not fill in the TOKEN at this step, and remove the quotation marks around NAME.

Pic4

After creating the function, edit it again and fill in the TOKEN at this time. Note that the value of TOKEN should not have quotation marks around it.

Pic5

Select the trigger method at the top and add a trigger method as shown in the figure below.

Pic6

Open the access path to check if there are any issues. If there are no issues, you can proceed to the next step.

3. Set up API Gateway#

Go to API Gateway, select the service on the left, and click on the service name to enter the settings.

Click on "Custom Domain", enter your domain name, and upload the certificate. If you don't enable HTTPS, you don't need to do this step. Set other settings as shown in the figure below.

Pic7

After adding it, select "Manage API", edit it, change the path to "/", check "Enable Response Integration", select HTML as the return type, and click "Complete" and "Publish".

4. Return to SCF and modify the environment variables#

The last step is to return to the cloud function and add an environment variable:

scf_base=/

Now you can access it by entering the domain name.

Pic8

With this, the setup of TCShare using SCF is complete.

Summary#

This article uses HeCaiyun as an example, and the setup for Tianyi Cloud Drive is similar. You can search for AK and SK on Github.

In my opinion, TCShare has a high level of completion overall, and I would like to express my gratitude to the original author for their efforts!

Once again, please note that SCF and API Gateway are not free products. Please be careful when using the free quota.

With this program, you can call audio and video resources from cloud drives in your articles.

Reference Articles#

Tencent Cloud SCF Setup TCShare Tianyi Cloud Directory List

TCShare: Cloud Drive Directory List, Supports Tianyi Cloud

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.