Anti-hotlinking method and device for resource file, storage medium and terminal equipment
By utilizing the Blob object and URL binding mechanism in the terminal device, the limitations of anti-theft chain and anti-crawler in the existing technology are solved, and efficient and secure temporary storage of resource files is achieved, reducing server burden, improving user experience and security is achieved. enhances anti-theft chain capability.
Patent Information
- Application Number
- CN202410990846.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2024-11-15
AI Technical Summary
The existing technology has limitations in anti-theft chain and anti-crawlers. Traditional methods are prone to tampering, IP address restrictions lack flexibility, and server processing load is too heavy, making it difficult to block highly specialized malicious attacks.
By implementing the anti-theft link method of resource files in terminal devices, using the Blob object and URL binding mechanism, temporarily store resources on the client, reduce the number of server requests and verifications, improve transmission efficiency and security, and bind resource addresses to window life cycles. To effectively prevent chain theft and crawling.
Reduce server burden, improve user experience and security, enhance anti-theft link and anti-crawling capabilities, reduce data conversion, improve resource access speed and security, and effectively prevent link theft and crawling behavior.
Smart Images

Figure CN118972108A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of network communications, and in particular to a method, device, storage medium and terminal device for preventing hotlinking of resource files. Background Art
[0002] In the era of high Internet penetration, the security of multimedia resources such as pictures, videos and PDF files on the Web platform and the performance of anti-hotlink mechanisms have become a widely focused issue in all walks of life. Although traditional anti-hotlink and anti-crawler technical means are effective, they also reveal limitations that cannot be ignored. For example, the simple Referer verification mechanism that relies solely on the Web server is prone to tampering, and the IP address restriction strategy is often cleverly circumvented by malicious users due to its lack of flexibility. In view of this, it is particularly urgent to explore and implement more efficient and stable protection strategies to ensure the legal and compliant use of multimedia resources. Common anti-hotlink and anti-crawler solutions focus on the fine configuration and enhanced verification level of the server. However, although such methods can improve resource protection capabilities to a certain extent, they inevitably increase the processing load of the server, and their defense effect is often inadequate in the face of highly professional malicious attacks, and it is difficult to completely block illegal hotlinking. Summary of the invention
[0003] The embodiments of the present application provide a resource file anti-hotlinking method, device, storage medium and terminal device, which can solve the problem that resource files are easily hotlinked in the prior art. The technical solution is as follows:
[0004] In a first aspect, an embodiment of the present application provides a method for preventing hotlinking of resource files, the method comprising:
[0005] Displaying a web page window in a browser in response to a user's opening instruction; wherein the web page window includes a resource file element, and the resource file element is associated with a resource file ID;
[0006] Sending a resource request message to the server; the resource request message carries: the resource file ID of the resource element and a response type field value representing binary;
[0007] Receiving a binary data stream corresponding to the resource file ID from the server, and storing the binary data stream in a local storage space;
[0008] Instantiate the binary data stream into a Blob object;
[0009] Create a URL for the Blob object;
[0010] Associating the URL with the resource file element in the web page window; the life cycle of the URL is the same as the life cycle of the web page window;
[0011] When an opening instruction of the resource file element is detected, the Blob object is searched in the local storage space according to the URL, and the resource file is opened in the web page window by parsing the Blob object;
[0012] When it is detected that the web page window is closed, the Blob object is deleted in the local storage space.
[0013] In a second aspect, an embodiment of the present application provides an anti-hotlink device for resource files, the device comprising:
[0014] A rendering unit, configured to display a web page window in a browser in response to an opening instruction of a user; wherein the web page window includes a resource file element, and the resource file element is associated with a resource file ID;
[0015] A sending unit, configured to send a resource request message to a server; the resource request message carries: a resource file ID of the resource element and a response type field value representing binary;
[0016] A writing unit, used for receiving a binary data stream corresponding to the resource file ID from the server, and storing the binary data stream in a local storage space;
[0017] A conversion unit, used for instantiating the binary data stream into a Blob object;
[0018] A creation unit, used to create a URL for the Blob object;
[0019] A binding unit, used to associate the URL with the resource file element in the web page window; the life cycle of the URL is the same as the life cycle of the web page window;
[0020] A parsing unit, configured to, when detecting an opening instruction of the resource file element, query the Blob object in the local storage space according to the URL, and parse the Blob object to open the resource file in the web page window;
[0021] The deleting unit is configured to delete the Blob object in the local storage space when detecting that the web page window is closed.
[0022] In a third aspect, an embodiment of the present application provides a computer storage medium, wherein the computer storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing the above-mentioned method steps.
[0023] In a fourth aspect, an embodiment of the present application provides a terminal device, which may include: a processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the above-mentioned method steps.
[0024] The beneficial effects brought about by the technical solutions provided by some embodiments of the present application include at least:
[0025] Temporarily store resources on the client side, reducing the number of times the server processes requests and verifications, reducing burdens and saving resource costs. Speed up resource access, improve stability, enhance user satisfaction, and help improve user retention and website traffic. By clarifying the binary response type, reduce data conversion, and improve transmission efficiency and security. Enhance anti-hotlink and anti-crawler capabilities: Bind the resource address to the window to effectively prevent hotlinking and crawling, and improve resource security. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0027] Figure 1 It is a schematic diagram of the network architecture provided by the embodiment of the present application;
[0028] Figure 2 It is a flowchart of a method for preventing hotlinking of resource files provided in an embodiment of the present application;
[0029] Figure 3 This is a schematic diagram of the structure of a resource file anti-hotlink device provided by the present application;
[0030] Figure 4 It is a structural diagram of a terminal device provided by this application. DETAILED DESCRIPTION
[0031] In order to make the objectives, technical solutions and advantages of the present application more clear, the embodiments of the present application will be further described in detail below with reference to the accompanying drawings.
[0032] It should be noted that the anti-hotlink method for resource files provided in the present application is generally executed by a terminal device, and correspondingly, the anti-hotlink device for resource files is generally arranged in the terminal device.
[0033] Figure 1 An exemplary system architecture of a resource file anti-hotlinking method or a resource file anti-hotlinking device that can be applied to the present application is shown.
[0034] like Figure 1 As shown, the system architecture may include: a terminal device 101 and a server 102. The terminal device 101 and the server 102 may communicate via a network, and the network is used as a medium for providing communication links between the above-mentioned units. The network may include various types of wired communication links or wireless communication links, for example: a wired communication link includes an optical fiber, a twisted pair or a coaxial cable, etc., and a wireless communication link includes a Bluetooth communication link, a wireless fidelity (WIreless-FIdelity, Wi-Fi) communication link or a microwave communication link, etc.
[0035] Among them, the server 102 stores real-time data of bonds, and the real-time data includes real-time bond issuance data, real-time bond issuer data and real-time news data. The terminal device 101 can obtain real-time data from the server 102, and then use the current model to predict the real-time data to obtain the prediction results of the bonds.
[0036] It should be noted that the terminal device 101 and the server 102 can be hardware or software. When the terminal device 101 and the server 102 are hardware, they can be implemented as a distributed server cluster consisting of multiple servers, or as a single server. When the terminal device 101 and the server 102 are software, they can be implemented as multiple software or software modules (for example, to provide distributed services), or as a single software or software module, which is not specifically limited here.
[0037] Various communication client applications can be installed on the terminal device of the present application, such as: video recording applications, video playback applications, voice interaction applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0038] The terminal device can be hardware or software. When the terminal device is hardware, it can be various terminal devices with a display screen, including but not limited to smart phones, tablet computers, laptops, and desktop computers. When the terminal device is software, it can be installed in the terminal devices listed above. It can be implemented as multiple software or software modules (for example: used to provide distributed services), or it can be implemented as a single software or software module, which is not specifically limited here.
[0039] When the terminal device is hardware, a display device and a camera may be installed thereon. The display device may be any device capable of realizing a display function, and the camera is used to collect video streams; for example, the display device may be a cathode ray tube display (CR), a light-emitting diode display (LED), an electronic ink screen, a liquid crystal display (LCD), a plasma display panel (PDP), etc. The user may use the display device on the terminal device to view displayed text, pictures, videos and other information.
[0040] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be used as required.
[0041] The following will be combined with the attached Figure 2 , the anti-hotlink method for resource files provided in the embodiment of the present application is described in detail. Among them, the anti-hotlink device for resource files in the embodiment of the present application can be Figure 1 The terminal device shown.
[0042] See also Figure 2 , is a flowchart of a method for preventing hotlinking of resource files provided in the present application embodiment. Figure 2 As shown, the method of the embodiment of the present application may include the following steps:
[0043] S201. Displaying a web page window in a browser in response to a user's opening instruction.
[0044] Among them, the user enters the URL in the address bar of the browser, clicks on a bookmark or link, triggering a request for a web page. The browser parses the URL (Uniform Resource Locator) entered by the user, determines the address and port of the target server, and then constructs an HTTP GET request. The browser sends the request to the corresponding server through the HTTP protocol. After receiving the request, the server searches for the corresponding HTML document according to the requested URL and prepares a response. The server returns the HTML document to the browser as the body of the HTTP response. After receiving the HTML document, the browser begins to parse the HTML code. The browser builds the HTML elements into a document object model (DOM) to represent the structure of the web page. The browser simultaneously loads and parses CSS style sheets and JavaScript scripts to apply styles and dynamic functions. During the DOM construction process, the browser identifies resource file elements in the web page (such as<img src="..."> 、 <audio src="...">etc.), and note the resource file IDs associated with these elements. The resource file ID is used to uniquely represent the identity of the resource file in the server. The resource file can be a picture file, video file, audio file or document file, etc.
[0045] In some embodiments of the present application, the permissions of the web page window can be controlled to improve security. The web page window is displayed in the browser in response to the user's opening instruction, including:
[0046] Receive an opening instruction from a user; the opening instruction is used to open a web page window through a browser;
[0047] Determining whether the user has permission to open the webpage window;
[0048] If yes, displaying the web page window in the browser;
[0049] If not, a prompt message indicating that there is no permission will be displayed in the browser.
[0050] Among them, the user issues an open instruction through the input device of the terminal device (such as a touch screen, keyboard, mouse, etc.). These instructions are first captured by the hardware interface of the terminal device and converted into electrical signals or digital signals. After receiving these signals, the input subsystem of the operating system (such as Android, iOS, Windows, macOS, etc.) parses the specific operation intention, that is, the user wants to open a certain web page window. According to the user's operation intention, the operating system sends instructions to the browser application that is running or needs to be started, requiring it to perform the operation of opening the web page window. This application has a built-in permission management system for controlling the user's access rights to system resources and application functions. After the browser application receives the instruction to open the web page window, it will first query whether the user has the permission to perform the operation. It usually involves checking the user's account status, role permissions, security policies, etc. According to the policy and configuration of the permission management system, the browser application will decide whether to allow or deny the user's request. If the user has permission, the browser application will parse the web page address (URL) requested by the user to determine the content that needs to be loaded. The browser sends a request to the specified server via the HTTP (or HTTPS) protocol to request to obtain the web page content. After the server responds to the request, the browser receives the HTML, CSS, JavaScript and other files of the web page, and uses its built-in rendering engine (such as Blink, Gecko, etc.) to parse and render these contents, and finally displays them to the user in the browser window. If the user does not have permission to open the web page window, the browser application will capture the permission check failure event and trigger the corresponding error handling process. The browser will display a prompt message to the user through the user interface (UI) to inform the user that the current operation is denied due to insufficient permissions, usually a pop-up window, prompt bar or error message on the page.
[0051] S202: Send a resource request message to the server.
[0052] Among them, in the JavaScript code of the webpage, the element (such as , <audio> , <video>, etc.), and obtain the resource file IDs associated with these elements. These IDs may be mapped to resources through custom attributes (such as data-id) or other logic. Create a new request object using the HTTP client library of the terminal device (such as the browser's FetchAPI, XMLHttpRequest object, or libraries such as http or axios in the Node.js environment). Set the request method to GET (or other applicable methods, but GET is usually used to obtain resources). Construct or obtain the server's API endpoint URL, which will be the destination to which the request will be sent. Note that this URL itself may not contain the resource file ID, because the ID will be sent in the request body or as a query parameter. Set the Accept field in the request header to application / octet-stream or other values indicating a binary response type to indicate that the server returns a binary data stream. If the server API is designed to receive the resource file ID through the request body, the ID needs to be serialized and sent in the request body. If the server API is designed to receive the ID through the query parameter of the URL, the query string needs to be appended to the URL, such as? id=resource file ID. Call the sending method of the request object (such as calling the fetch() function, calling the XMLHttpRequest.send() method, etc.) to send the constructed request to the server.
[0053] S203: Receive a binary data stream corresponding to the resource file ID from the server, and store the binary data stream in a local storage space.
[0054] After sending the request, the terminal device needs to listen for the response from the server. This is usually achieved through a callback function, the .then() method of Promise, or the async / await syntax. After receiving the response, first check the HTTP status code to ensure that the request was successful (such as 200OK). If the status code indicates an error (such as 404Not Found, 400InternalServer Error, etc.), appropriate error handling is required. Read the binary data stream from the response object.
[0055] If necessary, the binary data stream can be further processed, such as decompression, decryption, etc. This step depends on the specific content and requirements of the data stream. Choose an appropriate local storage method based on the characteristics and requirements of the terminal device. Common storage methods include: using localStorage (but pay attention to its limitations and unsuitability for storing large amounts of or binary data), IndexedDB, FileSystemAccessAPI (for modern browsers, allows data to be stored in the form of files), or WebSQL (although it is no longer recommended). Application side (such as Node.js or mobile applications): Use the file system API (such as the fs module of Node.js) to write files directly to disk.
[0056] Browser side: If you use the FileSystemAccessAPI, you can access and modify the local file system by requesting user authorization. Then, you can create a new file and write a binary data stream to the file. Application side: Use the corresponding file system API to open (or create) a file and write a binary data stream to the file. In Node.js, this usually involves using functions such as fs.writeFile() or fs.createWriteStream(). After the storage operation is completed, you can check the file in the local storage space to ensure that the data has been written successfully. This can be done by reading the file contents and comparing it with the original binary data stream (although it may not be practical for large files). If an error occurs during the storage process (such as insufficient disk space, file permission problems, etc.), appropriate error handling is required and the problem is reported to the user.
[0057] S204: Instantiate the binary data stream into a Blob object.
[0058] Among them, after receiving the response, the terminal device needs to read the data in the response body. Since the data is binary, it is usually returned in an ArrayBuffer, Stream (such as ReadableStream), or a platform-specific format (such as Buffer in Node.js). In JavaScript (especially in a browser environment), you can use the Blob constructor to create a new Blob object. The Blob object represents an immutable, raw data-like file object. If the response body is already an ArrayBuffer or ArrayBufferView (such as Uint8Array), you can use these data directly to create a Blob. If it is a Stream, you need to convert it to an ArrayBuffer or similar format first (note that in a browser environment, the conversion of Stream to ArrayBuffer may require additional processing, such as using the getReader() method of ReadableStream and looping to read data into Uint8Array). Use the Blob constructor and pass the prepared data (and optional MIME type) as parameters. For example: new Blob([data],{type:'application / octet-stream'}), where data is an array of ArrayBuffer, ArrayBufferView, Blob, or DOMString objects, which usually contains only one element; type is the MIME type, indicating the format of the data. If it is unknown or does not need to be specified, it can be omitted or set to 'application / octet-stream'.
[0059] S205: Create a URL for the Blob object.
[0060] The process of creating a URL for a Blob object in a Web environment is implemented through the URL.createObjectURL() method. This method accepts a Blob object (or a File object, because File inherits from Blob) as a parameter and returns a URL representing the content of the object. This URL is a reference to the internal data of the object, allowing users to reference the Blob object like a normal file URL.
[0061] S206: Associating the URL with the resource file element in the web page window.
[0062] The life cycle of a URL is the same as that of a web page window. Use the URL.createObjectURL(blob) method to convert the previously created Blob object into a URL that can be referenced in a web page. This URL is temporary and is only valid in the context of the current document (i.e., the web page window). Use JavaScript's DOM API (such as document.getElementById(), document.querySelector(), etc.) to obtain the resource file element in the web page that you want to associate with the BlobURL. Set the src attribute of the resource file element to the previously generated Blob URL. In this way, when the browser parses this element, it will try to load the URL pointed to by the src attribute, which is the content of your Blob object.
[0063] In most cases, the browser automatically manages the lifecycle of URLs generated by URL.createObjectURL(). When the document (web page window) containing these URLs is closed or unloaded, these URLs also become invalid and the browser releases the resources associated with them.
[0064] S207: When a preset trigger event occurs on a resource file element, a Blob object is searched in a local storage space based on the URL, and the resource file is opened in a web page window after parsing the Blob object.
[0065] The preset trigger time may be a mouse event or a keyboard event. The user may trigger the preset trigger event of the resource file through the mouse, keyboard or other input devices (such as clicking a link or button). JavaScript monitors the relevant events, locates the Blob object according to the URI, and ensures that the resource file is correctly loaded and displayed.
[0066] S208: When it is detected that the web page window is closed, the Blob object is deleted in the local storage space.
[0067] Among them, the browser provides a window closing event (such as beforeunload), which can be listened to to perform cleanup work. In the event handling function, use the URL.revokeObjectURL() method to release the previously created URI, and may also need to perform other cleanup operations, such as deleting the Blob object from memory (although the browser usually handles these automatically when the window is closed).
[0068] The embodiments of the present application have the following beneficial effects when evaluating the risk of a bond:
[0069] Reduce server burden: Compared with the traditional server-side anti-hotlink method, the present invention temporarily stores resources in the client browser memory, which reduces the server burden and saves server resource costs.
[0070] Improve user experience: Since resources are temporarily stored on the client, users can access the same resources faster and more stably, which improves the user experience and helps attract more users to visit the website.
[0071] Improve data transmission efficiency: By setting the response type to binary, the server is clearly informed of the type of data returned, which improves the efficiency and security of data transmission and reduces unnecessary data conversion processes.
[0072] Enhanced anti-hotlink capability: The life cycle of the resource address is bound to the current WEB window, implementing a safer and more efficient anti-hotlink and anti-crawler mechanism, effectively preventing hotlink and crawling behaviors.
[0073] Improved resource security: By temporarily storing resources on the client, resources can be effectively prevented from being illegally hotlinked or crawled, because the life cycle of the resource address is bound to the web page window, and closing the window destroys the resource, thereby protecting the security of the resource.
[0074] Reduce server burden: Temporarily storing resources in the client browser memory reduces the burden on the server, avoids the problem of frequent request processing and verification in traditional server-side anti-hotlinking methods, and saves server resource costs.
[0075] Improve user experience: Resources are temporarily stored on the client, and user access is faster and more stable, which improves user experience and helps increase user retention and website traffic.
[0076] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0077] See also Figure 4 , which shows a schematic diagram of the structure of an anti-hotlink device for resource files provided by an exemplary embodiment of the present application, hereinafter referred to as device 3. The device 3 can be implemented as all or part of the terminal device through software, hardware or a combination of both. The device 3 includes: a rendering unit 301, a sending unit 302, a writing unit 303, a conversion unit 304, a creation unit 305, a binding unit 306, a parsing unit 307, and a deletion unit 308.
[0078] The rendering unit 301 is used to display a web page window in the browser in response to an opening instruction of the user; wherein the web page window includes a resource file element, and the resource file element is associated with a resource file ID;
[0079] The sending unit 302 is used to send a resource request message to the server; the resource request message carries: the resource file ID of the resource element and a response type field value representing binary;
[0080] The writing unit 303 is used to receive the binary data stream corresponding to the resource file ID from the server, and store the binary data stream in the local storage space;
[0081] A conversion unit 304, configured to instantiate the binary data stream into a Blob object;
[0082] A creation unit 305, configured to create a URL for the Blob object;
[0083] A binding unit 306, used to associate the URL with the resource file element in the web page window; the life cycle of the URL is the same as the life cycle of the web page window;
[0084] The parsing unit 307 is configured to, when detecting an opening instruction of the resource file element, query the Blob object in the local storage space according to the URL, and parse the Blob object to open the resource file in the web page window;
[0085] The deleting unit 308 is configured to delete the Blob object in the local storage space when it is detected that the webpage window is closed.
[0086] In one or more possible embodiments, the type of the resource request message is XHR.
[0087] In one or more possible embodiments, the local storage space is memory, IndexedDB or LocalStorage.
[0088] In one or more possible embodiments, displaying a web page window in a browser in response to an opening instruction from a user includes:
[0089] Receive an opening instruction from a user; the opening instruction is used to open a web page window through a browser;
[0090] Determining whether the user has permission to open the webpage window;
[0091] If yes, displaying the web page window in the browser;
[0092] If not, a prompt message indicating that there is no permission will be displayed in the browser.
[0093] In one or more possible embodiments, the binary data stream is encrypted.
[0094] In one or more possible embodiments, the resource file is a picture file, an audio file or a video file.
[0095] In one or more possible embodiments, the URL.createObjectURL() method is used to create a URL for the Blob object.
[0096] It should be noted that when the device 3 provided in the above embodiment executes the anti-hotlink method for resource files, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the above functions. In addition, the anti-hotlink device for resource files provided in the above embodiment and the anti-hotlink method embodiment for resource files belong to the same concept. The implementation process is detailed in the method embodiment, which will not be repeated here.
[0097] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0098] The present application also provides a computer storage medium, which can store multiple instructions, and the instructions are suitable for being loaded and executed by a processor as described above. Figure 2 The method steps of the embodiment shown in the figure can be found in the specific implementation process. Figure 2 The specific description of the illustrated embodiment will not be repeated here.
[0099] The present application also provides a computer program product, which stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the anti-hotlinking method for resource files as described in the above embodiments.
[0100] See also Figure 4 , which is a schematic diagram of the structure of a terminal device provided in an embodiment of the present application. Figure 4 As shown, the terminal device 400 may include: at least one processor 401 , at least one network interface 404 , a user interface 403 , a memory 405 , and at least one communication bus 402 .
[0101] The communication bus 402 is used to realize the connection and communication between these components.
[0102] The user interface 403 may include a display screen (Display) and a camera (Camera), and the optional user interface 403 may also include a standard wired interface and a wireless interface.
[0103] The network interface 404 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).
[0104] Among them, the processor 401 may include one or more processing cores. The processor 401 uses various interfaces and lines to connect the various parts of the entire terminal device 400, and executes various functions and processes data of the terminal device 400 by running or executing instructions, programs, code sets or instruction sets stored in the memory 405, and calling data stored in the memory 405. Optionally, the processor 401 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 401 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 401, and it can be implemented separately through a chip.
[0105] Among them, the memory 405 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory). Optionally, the memory 405 includes a non-transitory computer-readable storage medium. The memory 405 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 405 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned method embodiments, etc.; the data storage area may store data involved in the above-mentioned method embodiments, etc. The memory 405 may optionally be at least one storage device located away from the aforementioned processor 401. As Figure 4 As shown, the memory 405 as a computer storage medium may include an operating system, a network communication module, a user interface module, and an application program.
[0106] exist Figure 4 In the terminal device 400 shown in FIG. 1 , the user interface 403 is mainly used to provide an input interface for the user and obtain the data input by the user; and the processor 401 can be used to call the application stored in the memory 405 and specifically execute the following steps: Figure 2 The specific process can be referred to Figure 2 As shown, no further description is given here.
[0107] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only storage memory, or a random access memory, etc.
[0108] The above disclosure is only the preferred embodiment of the present application, which certainly cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.< / video> < / audio> < / audio>
Claims
1. A method for preventing hotlinking of resource files, characterized in that: include: Displaying a web page window in a browser in response to a user's opening instruction; wherein the web page window includes a resource file element, and the resource file element is associated with a resource file ID; Sending a resource request message to the server; the resource request message carries: the resource file ID of the resource element and a response type field value representing binary; Receiving a binary data stream corresponding to the resource file ID from the server, and storing the binary data stream in a local storage space; Instantiate the binary data stream into a Blob object; Create a URL for the Blob object; Associating the URL with the resource file element in the web page window; the life cycle of the URL is the same as the life cycle of the web page window; When an opening instruction of the resource file element is detected, the Blob object is searched in the local storage space according to the URL, and the resource file is opened in the web page window by parsing the Blob object; When it is detected that the web page window is closed, the Blob object is deleted in the local storage space.
2. The method according to claim 1, characterized in that The type of the resource request message is XHR.
3. The method according to claim 1 or 2, characterized in that: The local storage space is memory, IndexedDB or Local Storage.
4. The method according to claim 3, characterized in that The step of displaying a webpage window in a browser in response to an opening instruction from a user comprises: Receive an opening instruction from a user; the opening instruction is used to open a web page window through a browser; Determining whether the user has permission to open the webpage window; If yes, displaying the web page window in the browser; If not, a prompt message indicating that there is no permission will be displayed in the browser.
5. The method according to claim 1, 2 or 4, characterized in that: Encrypts binary data streams.
6. The method according to claim 5, characterized in that The resource file is a picture file, an audio file or a video file.
7. The method according to claim 1 or 2 or 4 or 6, characterized in that: Create a URL for the Blob object using the URL.createObjectURL() method.
8. A resource file anti-hotlink device, characterized in that: include: A rendering unit, configured to display a web page window in a browser in response to an opening instruction of a user; wherein the web page window includes a resource file element, and the resource file element is associated with a resource file ID; A sending unit, configured to send a resource request message to a server; the resource request message carries: a resource file ID of the resource element and a response type field value representing binary; A writing unit, used for receiving a binary data stream corresponding to the resource file ID from the server, and storing the binary data stream in a local storage space; A conversion unit, used for instantiating the binary data stream into a Blob object; A creation unit, used to create a URL for the Blob object; A binding unit, used to associate the URL with the resource file element in the web page window; the life cycle of the URL is the same as the life cycle of the web page window; A parsing unit, configured to, when detecting an opening instruction of the resource file element, query the Blob object in the local storage space according to the URL, and parse the Blob object to open the resource file in the web page window; The deleting unit is configured to delete the Blob object in the local storage space when detecting that the web page window is closed.
9. A computer storage medium, characterized in that The computer storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the method steps according to any one of claims 1 to 7.
10. A terminal device, characterized in that: include: A processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the method steps as claimed in any one of claims 1 to 7.
