Tag Archives: The front-end development

Image proxy settings Flash + JavaScript

The article directories
Problem description idea specific implementation front end back end

Problem description
If is request http://www.example.com/image1.png picture originally, now ask for pictures, https://www.petal.social/image/www.example.com/image1.png you will need to do an image proxy
(request pictures to our own when the server request, then our HTTP server request images, the result of the HTTP in the way back to the web site of the HTTPS)
Train of thought
First, add an API locally for the front-end request that returns the modified image URL
The specific implementation
The front end
Original version:

showImage(url) {
    if (url.startsWith('http://')) {
        if (url.includes('qpic.cn') || url.includes('gtimg.cn')) {
            return url.replace('http://', 'https://')
        } else {
            return return 'https://demo.cloudimg.io/v7/' + url
        }
    } else {
        return url
    }
}

Image URL contains /, so in Flask is mistaken for routing calls, so you need to for the original URL with Base64 encryption
modify after:

import {Base64} from 'js-base64'
const BASE_URL = 'http://localhost:5000'
// const BASE_URL = 'https://www.petal.social'
showImage(url) {
    if (url.startsWith('http://')) {
        if (url.includes('qpic.cn') || url.includes('gtimg.cn')) {
            return url.replace('http://', 'https://')
        } else {
            return BASE_URL + '/api/v1/image/' + Base64.encode(url)
        }
    } else {
        return url
    }
}

The back-end

from flask_restplus import Namespace, Resource
from flask import request, make_response
from maintenance import check_maintenance, not_under_maintenance
import requests
from flask import Response, stream_with_context
import base64
image_api = Namespace('image', description='image related public interface')

@image_api.route('/<image_url>')
@image_api.param('image_url', 'The original image url')
class Image(Resource):
    @image_api.doc('get_image_url')
    @not_under_maintenance
    def get(self, image_url):
        check_maintenance()
        image_url = base64.b64decode(image_url)
        res = requests.get(image_url, stream = True)
        return Response(stream_with_context(res.iter_content(2048)), content_type = res.headers['content-type']) 

NPM install error | gyp err! Configure error

gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/Users/wlk_yodinfo/Documents/front_projects/diy-cli/node_modules/fsevents/build'
gyp ERR! System Darwin 18.5.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/Users/wlk_yodinfo/Documents/front_projects/diy-cli/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node" "--module_name=fse" "--module_path=/Users/wlk_yodinfo/Documents/front_projects/diy-cli/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64" "--napi_version=4" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v64"
gyp ERR! cwd /Users/wlk_yodinfo/Documents/front_projects/diy-cli/node_modules/fsevents
gyp ERR! node -v v10.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

Analysis reason:
packet download security problem, guess NPM download default is to pull a safe package to node_modules, so if it is judged not safe enough, will not be pulled down, and will throw an error record
Solutions:

sudo npm i --unsafe-perm

If not, try this:

sudo rm -rf ~/.node-gyp
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo npm i --unsafe-perm

Error: enoent: no such file or directory, stat ‘/ usr / local / var / www / / book/gitbook/git

After gitbook every edit, there will be an Error, which will cause the service started by gitbook Serve to stop. The Error message is :gitbook edit Error: Error: ENOENT: no such file or directory, stat ‘/usr/local/var/www/… /_book/gitbook/gitbook-plugin-livereload/plugin.js’
In the background, a gitbook was newly installed. Every time I edited the MD file in the project, I would catch the above error, which caused me to stop the service started by Gitbook Serve and could not properly browse the newly edited Gitbook.
At the beginning, I didn’t pay attention to the error report. Later, I modified and edited the file several times, and found that after each modification, gitbook service would stop and the error in the paper would be reported. Only to find that this is not a mistake of my operation, but the GITbok has a problem, find a problem for a while, no idea, baidu once, the original gitbook itself bug, the original gitbook is a configuration to the wrong configuration. The specific modification methods are as follows:
1. Find gitbook’s configuration file address (Mac system) in the user directory: CD ~ can jump to the current user’s user directory
2. Find ~ /. Gitbook/versions/3.2.3/lib/output/website/copyPluginAssets js file, and then find this file inside all confirm configuration items (2) total, will change the original values true or false.

confirm: false

There are 2 places in total, just change them.