banner
百科资源

百科资源

Telegraph-Image free self-built image hosting service adds backend image management.

The previously released code had a logic error due to my poor mental state from staying up late. When writing the code, I made the most basic logic mistake. It should have been if (check if the kv environment variable is set), then (write the image to kv storage when the image is first loaded). But for some reason yesterday, whether it was a short circuit in my brain or something else, I wrote the if condition statement in reverse. It became if (the kv environment variable is not set), then (write the image to kv storage when the image is first loaded). But obviously, if the kv environment variable is not set, it is impossible to successfully write to kv storage. This caused some experts to encounter the error "Error 1101 Worker threw exception" during deployment yesterday. Although the experts who set the kv environment variable can run the program normally, the backend management cannot record images because the program will not execute the write operation. I am very sorry for this and apologize for the inconvenience caused to all the experts. The problem should be fixed now. Please deploy the latest version of the code, and thank you to @雾山 @mikj521 @那山很优雅 @3514088137 @hiing @telnetpig @mourner and other experts for their feedback. Due to staying up late for several days in a row, my body couldn't handle it anymore yesterday, so I went to sleep and couldn't reply in time. I'm sorry!

I casually mentioned that if the project on GitHub exceeds 500 stars, I will update the image management feature. I originally thought that a small image hosting program would never reach 500 stars, but unexpectedly, the experts were very enthusiastic. Goodness, in just a few months, I received over 600 stars. Since I promised, I had to reluctantly develop the image management feature.

Although I encountered many difficulties during development and spent more time than I expected, I kept delaying the release. After staying up for several nights in a row, I finally managed to release this update before the Spring Festival. I would like to take this opportunity to wish all the experts a happy Spring Festival! I hope you can achieve your dreams in the new year!

Without further ado, here is the code:
https://github.com/cf-pages/Telegraph-Image

For experts who have not deployed before, you can directly fork this repository and deploy it in the Cloudflare Pages backend.

Now let me introduce the main content of this update:

  1. The long-awaited image management feature is now available. It is disabled by default. To enable it, please deploy the code and then go to the backend and click "Settings" -> "Functions" -> "KV Namespace Binding" -> "Edit Binding" -> "Variable Name" and enter: img_url. Choose the KV storage space you created in advance. After enabling, you can open the backend management page by visiting http(s)://yourdomain/admin.
    Image [1]-Telegraph-Image Free Self-built Image Hosting Adds Backend Image Management-Wikipedia Resources
    Image [2]-Telegraph-Image Free Self-built Image Hosting Adds Backend Image Management-Wikipedia Resources
    (For how to create a KV storage space, please refer to: https://github.com/xyTom/Url-Shorten-Worker/#%E5%8E%BBworkers-kv%E4%B8%AD%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4)

  2. The backend management page now has a login verification feature, which is also disabled by default. To enable it, please deploy the code and then go to the backend and click "Settings" -> "Environment Variables" -> "Define Variables for Production Environment" -> "Edit Variables".

"Variable Name" "Value"
BASIC_USER =
BASIC_PASS =
Image [3]-Telegraph-Image Free Self-built Image Hosting Adds Backend Image Management-Wikipedia Resources

Of course, you can also not set these two values, so that no verification is required when accessing the backend management page, and the login step is skipped. This design allows you to use Cloudflare Access to support email verification code login, Microsoft account login, GitHub account login, and other functions, which can be integrated with the login methods on your domain, without the need to remember another set of account passwords for the backend. For adding Cloudflare Access, please refer to the official documentation. Experts are also welcome to share tutorials. Note that the protected paths include /admin and /api/manage/*.

  1. Added image total count statistics. When the image management feature is enabled, you can view the number of images in the record at the top of the backend.
    Image [4]-Telegraph-Image Free Self-built Image Hosting Adds Backend Image Management-Wikipedia Resources

  2. Added image file name search. When the image management feature is enabled, you can use the search box in the backend to search for images by file name and quickly locate the images that need to be managed.
    Image [5]-Telegraph-Image Free Self-built Image Hosting Adds Backend Image Management-Wikipedia Resources

  3. Added image status display. When the image management feature is enabled, you can view the current status of the image in the backend { "ListType": "None", "TimeStamp": 1673984678274 }. ListType represents whether the image is in the whitelist or blacklist. None means it is neither in the blacklist nor whitelist, White means it is in the whitelist, Block means it is in the blacklist, and TimeStamp is the timestamp when the image was first loaded. If the image review API is enabled, the result of the image review will also be displayed here with a label.

Image [6]-Telegraph-Image Free Self-built Image Hosting Adds Backend Image Management-Wikipedia Resources

  1. Added blacklist function. When the image management feature is enabled, you can manually add images to the blacklist in the backend. Images in the blacklist will not be loaded normally.
    Image [7]-Telegraph-Image Free Self-built Image Hosting Adds Backend Image Management-Wikipedia Resources

  2. Added whitelist function. When the image management feature is enabled, you can manually add images to the whitelist in the backend. Images in the whitelist will be loaded normally regardless of the result of the image review API.
    Image [8]-Telegraph-Image Free Self-built Image Hosting Adds Backend Image Management-Wikipedia Resources

  3. Added record deletion function. When the image management feature is enabled, you can manually delete image records in the backend, which will no longer be displayed in the backend. Unless someone uploads and loads the image again, please note that we cannot delete the original uploaded image stored on Telegraph's server. We can only block the image from loading using the blacklist function mentioned above.

  4. Added program running mode: whitelist mode. When the image management feature is enabled, in addition to the default mode, this update also adds a new running mode. In this mode, only images added to the whitelist will be loaded, and uploaded images need to be approved before they can be displayed. This maximizes the prevention of loading inappropriate images. To enable this mode, please set the environment variable: WhiteList_Mode=="true".

  5. Added image preview function in the backend. When the image management feature is enabled, you can preview the images loaded through your domain in the backend. Click on the image to zoom in, zoom out, rotate, and perform other operations.
    Image [9]-Telegraph-Image Free Self-built Image Hosting Adds Backend Image Management-Wikipedia Resources

This update has many new features and can be considered a major update. Almost all of the backend code has been rewritten, which took a lot of time. I hope the experts find it useful. Considering that I stayed up late for so long, I hope you can give me a free star on GitHub and help me promote it to more people. Thank you very much!

For those who have already deployed, how to update?
Actually, updating is very simple. Just follow the update content above, go to the Cloudflare Pages backend, set the environment variables you need in advance and bind them to the KV namespace, then go to the repository you forked on GitHub and select "Sync fork" -> "Update branch" one by one. Wait for a while, when Cloudflare Pages detects that your repository has been updated, it will automatically deploy the latest code.

Image [10]-Telegraph-Image Free Self-built Image Hosting Adds Backend Image Management-Wikipedia Resources

Some notes:
Cloudflare KV has a daily free write quota of 1000 times. Each time a new image is loaded, it will consume this write quota. If it exceeds this quota, the backend image management will not be able to record the newly loaded images.
There is a maximum of 100,000 free read operations per day. Each time an image is loaded, it will consume this quota (in the absence of caching, if your domain has caching enabled in Cloudflare, it will only consume this quota when the cache is missed). Exceeding this quota may cause the blacklist and whitelist functions to fail.
There is a maximum of 1,000 free delete operations per day. Each image record will consume this quota. Exceeding this quota will prevent the deletion of image records.
There is a maximum of 1,000 free list operations per day. Each time you open or refresh the backend/admin, it will consume this quota. Exceeding this quota will affect the backend image management.

In most cases, these free quotas are generally sufficient and can be slightly exceeded. If the quota is exceeded, it does not mean it will be immediately disabled. Each quota is calculated separately. If one operation exceeds the free quota, only that operation will be disabled, and other functions will not be affected. Even if my free write quota is used up, my read and write functions will not be affected. The images can still be loaded normally, but I will not be able to see the new images in the image management backend.

If you feel that the free quota is not enough, you can purchase the paid version of Cloudflare Workers from Cloudflare, starting at $5 per month, and it is charged based on usage, without the above quota restrictions (why do I feel like I'm advertising for Cloudflare? Cloudflare, please pay me for the advertisement /doge).

The conclusions drawn from the above notes are based on repeated testing over many days and should be valid. However, it cannot be ruled out that Cloudflare may suddenly change its policies in the future. Secondly, all the features released in this update have been tested repeatedly. If you encounter bugs during use, it may be caused by Cloudflare or browser caching. You can try clearing the cache and trying again. In addition, changes to environment variables will take effect during the next deployment. If you have changed the environment variables, please remember to redeploy.
Image [11]-Telegraph-Image Free Self-built Image Hosting Adds Backend Image Management-Wikipedia Resources

If you have tried clearing the cache, redeploying, and still have problems, you can raise an issue on GitHub for feedback. After all, this update has many features, and my skills and time are limited. Although I have done repeated testing, it is still difficult to test every feature and every situation. It is inevitable to encounter bugs. It was not easy for me to release this update before the new year. I encountered many difficulties during development and wanted to give up many times, thinking about shelving it. But when I think about so many experts (600+ stars) silently supporting me, giving me little stars on GitHub, I feel that I cannot let down the kindness of the experts. Regardless, I must grit my teeth and release the image management feature.

Demo address: https://im.gurl.eu.org/

Article source: http://www.caidianhe.com/jishu/5676.html

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