CN118626135A - File processing method, device, computer equipment and storage medium - Google Patents
File processing method, device, computer equipment and storage medium Download PDFInfo
- Publication number
- CN118626135A CN118626135A CN202410718867.4A CN202410718867A CN118626135A CN 118626135 A CN118626135 A CN 118626135A CN 202410718867 A CN202410718867 A CN 202410718867A CN 118626135 A CN118626135 A CN 118626135A
- Authority
- CN
- China
- Prior art keywords
- resource
- file
- files
- static
- resource file
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000003672 processing method Methods 0.000 title claims abstract description 16
- 230000003068 static effect Effects 0.000 claims abstract description 338
- 238000004806 packaging method and process Methods 0.000 claims abstract description 116
- 238000013515 script Methods 0.000 claims abstract description 86
- 238000000034 method Methods 0.000 claims abstract description 36
- 238000004590 computer program Methods 0.000 claims abstract description 32
- 238000012545 processing Methods 0.000 claims description 35
- 238000005457 optimization Methods 0.000 claims description 13
- 238000012858 packaging process Methods 0.000 claims description 6
- 238000010586 diagram Methods 0.000 description 7
- 230000008569 process Effects 0.000 description 7
- 238000012216 screening Methods 0.000 description 7
- 230000008859 change Effects 0.000 description 5
- 238000011161 development Methods 0.000 description 4
- 230000006870 function Effects 0.000 description 4
- 238000004891 communication Methods 0.000 description 3
- 230000006835 compression Effects 0.000 description 3
- 238000007906 compression Methods 0.000 description 3
- 238000012423 maintenance Methods 0.000 description 3
- 230000004044 response Effects 0.000 description 3
- 101001121408 Homo sapiens L-amino-acid oxidase Proteins 0.000 description 2
- 102100026388 L-amino-acid oxidase Human genes 0.000 description 2
- 238000013500 data storage Methods 0.000 description 2
- 230000000694 effects Effects 0.000 description 2
- 238000000605 extraction Methods 0.000 description 2
- OKTJSMMVPCPJKN-UHFFFAOYSA-N Carbon Chemical compound [C] OKTJSMMVPCPJKN-UHFFFAOYSA-N 0.000 description 1
- 101000827703 Homo sapiens Polyphosphoinositide phosphatase Proteins 0.000 description 1
- 102100023591 Polyphosphoinositide phosphatase Human genes 0.000 description 1
- 101100012902 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) FIG2 gene Proteins 0.000 description 1
- 101100233916 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) KAR5 gene Proteins 0.000 description 1
- 238000004458 analytical method Methods 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 238000004422 calculation algorithm Methods 0.000 description 1
- 238000006243 chemical reaction Methods 0.000 description 1
- 238000012790 confirmation Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 229910021389 graphene Inorganic materials 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000002360 preparation method Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/71—Version control; Configuration management
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/44—Encoding
- G06F8/443—Optimisation
- G06F8/4434—Reducing the memory space required by the program code
- G06F8/4435—Detection or removal of dead or redundant code
Landscapes
- Engineering & Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computer Security & Cryptography (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
Description
技术领域Technical Field
本申请涉及大数据技术领域,特别是涉及一种文件处理方法、装置、计算机设备、存储介质和计算机程序产品。The present application relates to the field of big data technology, and in particular to a file processing method, apparatus, computer equipment, storage medium and computer program product.
背景技术Background Art
代码打包流程的输出为程序包,在某些场景下,程序包的大小存在限制,需要再开发阶段对程序包进行优化,以使程序包的所占空间满足存储空间要求。The output of the code packaging process is a program package. In some scenarios, the size of the program package is limited, and the program package needs to be optimized during the development phase so that the space occupied by the program package meets the storage space requirements.
现有的方式中,对代码文件进行简化,具体可以优化代码结构、删除不必要的代码、采用压缩算法的方式,减小代码体积,减少程序包所占空间,这种方式虽然一定程度上减小了代码体积,但同时延长了打包准备时长,降低了打包效率。In the existing method, the code files are simplified, specifically by optimizing the code structure, deleting unnecessary code, and using compression algorithms to reduce the code size and the space occupied by the program package. Although this method reduces the code size to a certain extent, it also prolongs the packaging preparation time and reduces the packaging efficiency.
发明内容Summary of the invention
基于此,有必要针对上述技术问题,提供一种能够提高打包效率的文件处理方法、装置、计算机设备、计算机可读存储介质和计算机程序产品。Based on this, it is necessary to provide a file processing method, device, computer equipment, computer-readable storage medium and computer program product that can improve packaging efficiency in response to the above technical problems.
第一方面,本申请提供了一种文件处理方法。所述方法包括:In a first aspect, the present application provides a file processing method. The method comprises:
获取代码打包脚本以及多个静态资源文件;所述代码打包脚本携带有配置文件;执行代码打包脚本,基于所述配置文件中的配置资源属性,分别对各所述静态资源文件各自的静态资源属性进行匹配,得到目标资源文件和基础资源文件,所述目标资源文件为匹配成功的静态资源属性对应的静态资源文件,所述基础资源文件为匹配失败的静态资源属性对应的静态资源文件;将所述目标资源文件上传至服务器,得到所述目标资源文件在所述服务器的在线地址;对包含所述在线地址、所述基础资源文件、所述基础资源文件的本地地址的待打包文件打包处理,得到程序包。Obtain a code packaging script and multiple static resource files; the code packaging script carries a configuration file; execute the code packaging script, and based on the configuration resource attributes in the configuration file, match the static resource attributes of each of the static resource files respectively to obtain a target resource file and a basic resource file, the target resource file is a static resource file corresponding to the static resource attribute that successfully matches, and the basic resource file is a static resource file corresponding to the static resource attribute that fails to match; upload the target resource file to a server to obtain an online address of the target resource file on the server; package the files to be packaged that include the online address, the basic resource file, and the local address of the basic resource file to obtain a program package.
在其中一个实施例中,所述配置资源属性包括资源类型条件和资源大小条件;所述静态资源属性包括静态资源类型和静态资源大小;所述执行代码打包脚本,基于所述配置文件中的配置资源属性,分别对各所述静态资源文件各自的静态资源属性进行匹配,得到目标资源文件和基础资源文件,包括:执行代码打包脚本,基于所述配置文件中的资源类型条件,分别对各所述静态资源文件各自的静态资源类型进行匹配,得到所述资源类型条件分别与各所述静态资源文件之间的类型匹配结果;基于所述配置文件中的资源大小条件,分别对各所述静态资源文件各自的静态资源大小进行匹配,得到所述资源大小条件分别与各所述静态资源文件之间的大小匹配结果;根据所述类型匹配结果和所述大小匹配结果,将各所述静态资源文件划分为目标资源文件和基础资源文件。In one of the embodiments, the configuration resource attributes include resource type conditions and resource size conditions; the static resource attributes include static resource types and static resource sizes; the execution code packaging script, based on the configuration resource attributes in the configuration file, matches the static resource attributes of each of the static resource files respectively to obtain target resource files and basic resource files, including: executing the code packaging script, based on the resource type conditions in the configuration file, matches the static resource types of each of the static resource files respectively to obtain type matching results between the resource type conditions and each of the static resource files respectively; based on the resource size conditions in the configuration file, matches the static resource sizes of each of the static resource files respectively to obtain size matching results between the resource size conditions and each of the static resource files respectively; and dividing each of the static resource files into target resource files and basic resource files according to the type matching results and the size matching results.
在其中一个实施例中,所述根据所述类型匹配结果和所述大小匹配结果,将各所述静态资源文件划分为目标资源文件和基础资源文件,包括:按照各所述类型匹配结果,筛选各所述静态资源文件中资源类型匹配成功的静态资源文件;按照各所述大小匹配结果,筛选各所述静态资源文件中资源大小匹配成功的静态资源文件;合并所述资源类型匹配成功的静态资源文件和所述资源大小匹配成功的静态资源文件,得到目标资源文件;并将除所述目标资源文件以外各所述静态资源文件确定为基础资源文件。In one of the embodiments, the static resource files are divided into target resource files and basic resource files according to the type matching results and the size matching results, including: screening the static resource files whose resource types are successfully matched in the static resource files according to the type matching results; screening the static resource files whose resource sizes are successfully matched in the static resource files according to the size matching results; merging the static resource files whose resource types are successfully matched and the static resource files whose resource sizes are successfully matched to obtain the target resource files; and determining the static resource files except the target resource files as basic resource files.
在其中一个实施例中,所述将所述目标资源文件上传至服务器,得到所述目标资源文件在所述服务器的在线地址,包括:确定与所述目标资源文件的静态资源属性匹配的多个候选服务器;按照各所述候选服务器各自的负载特征,在各所述候选服务器中选取目标服务器;将所述目标资源文件上传至所述目标服务器,接收所述目标服务器发送的所述目标资源文件在所述目标服务器的在线地址。In one of the embodiments, uploading the target resource file to the server and obtaining the online address of the target resource file on the server includes: determining multiple candidate servers that match the static resource attributes of the target resource file; selecting a target server from each candidate server according to the load characteristics of each candidate server; uploading the target resource file to the target server, and receiving the online address of the target resource file on the target server sent by the target server.
在其中一个实施例中,所述对包含所述在线地址、所述基础资源文件、所述基础资源文件的本地地址的待打包文件打包处理,得到程序包,包括:在资源文件库中提取与所述基础资源文件存在分辨率关联关系的候选资源文件;确定基础资源文件的基础本地地址,以及所述候选资源文件的候选本地地址;对包含所述在线地址、基础本地地址、所述候选本地地址、所述基础资源文件、所述候选资源文件的待打包文件打包处理,得到程序包。In one of the embodiments, the packaging of the files to be packaged including the online address, the basic resource file, and the local address of the basic resource file to obtain a program package includes: extracting candidate resource files that have a resolution association relationship with the basic resource file from a resource file library; determining the basic local address of the basic resource file and the candidate local addresses of the candidate resource files; packaging the files to be packaged including the online address, the basic local address, the candidate local address, the basic resource file, and the candidate resource file to obtain a program package.
在其中一个实施例中,所述获取多个静态资源文件,包括:获取待打包文件中的项目代码;扫描所述项目代码,得到所述项目代码对应的多个备选资源文件;对各所述备选资源文件进行文件类优化处理,得到多个静态资源文件;所述对包含所述在线地址、所述基础资源文件、所述基础资源文件的本地地址的待打包文件打包处理,得到程序包,包括:对包含所述在线地址、所述基础资源文件的本地地址的项目代码,以及所述基础资源文件打包处理,得到程序包。In one of the embodiments, the obtaining of multiple static resource files includes: obtaining a project code in a file to be packaged; scanning the project code to obtain multiple candidate resource files corresponding to the project code; performing file class optimization processing on each of the candidate resource files to obtain multiple static resource files; the packaging processing of the file to be packaged including the online address, the basic resource file, and the local address of the basic resource file to obtain a program package includes: packaging processing of the project code including the online address, the local address of the basic resource file, and the basic resource file to obtain a program package.
第二方面,本申请还提供了一种文件处理装置。所述装置包括:In a second aspect, the present application also provides a file processing device. The device comprises:
获取模块,用于获取代码打包脚本以及多个静态资源文件;所述代码打包脚本携带有配置文件;匹配模块,用于执行代码打包脚本,基于所述配置文件中的配置资源属性,分别对各所述静态资源文件各自的静态资源属性进行匹配,得到目标资源文件和基础资源文件,所述目标资源文件为匹配成功的静态资源属性对应的静态资源文件,所述基础资源文件为匹配失败的静态资源属性对应的静态资源文件;上传模块,用于将所述目标资源文件上传至服务器,得到所述目标资源文件在所述服务器的在线地址;打包模块,用于对包含所述在线地址、所述基础资源文件、所述基础资源文件的本地地址的待打包文件打包处理,得到程序包。An acquisition module is used to acquire a code packaging script and multiple static resource files; the code packaging script carries a configuration file; a matching module is used to execute the code packaging script, and based on the configuration resource attributes in the configuration file, the static resource attributes of each of the static resource files are matched to obtain a target resource file and a basic resource file, the target resource file is a static resource file corresponding to a successfully matched static resource attribute, and the basic resource file is a static resource file corresponding to a failed matching static resource attribute; an upload module is used to upload the target resource file to a server to obtain an online address of the target resource file on the server; a packaging module is used to package and process the files to be packaged that include the online address, the basic resource file, and the local address of the basic resource file to obtain a program package.
第三方面,本申请还提供了一种计算机设备。所述计算机设备包括存储器和处理器,所述存储器存储有计算机程序,所述处理器执行所述计算机程序时实现以下步骤:In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
获取代码打包脚本以及多个静态资源文件,所述代码打包脚本携带有配置文件;执行代码打包脚本,基于所述配置文件中的配置资源属性,分别对各所述静态资源文件各自的静态资源属性进行匹配,得到目标资源文件和基础资源文件,所述目标资源文件为匹配成功的静态资源属性对应的静态资源文件,所述基础资源文件为匹配失败的静态资源属性对应的静态资源文件;将所述目标资源文件上传至服务器,得到所述目标资源文件在所述服务器的在线地址;对包含所述在线地址、所述基础资源文件、所述基础资源文件的本地地址的待打包文件打包处理,得到程序包。Obtain a code packaging script and multiple static resource files, wherein the code packaging script carries a configuration file; execute the code packaging script, and match the static resource attributes of each of the static resource files based on the configuration resource attributes in the configuration file to obtain a target resource file and a basic resource file, wherein the target resource file is a static resource file corresponding to a successfully matched static resource attribute, and the basic resource file is a static resource file corresponding to a failedly matched static resource attribute; upload the target resource file to a server to obtain an online address of the target resource file on the server; package the files to be packaged, which include the online address, the basic resource file, and the local address of the basic resource file, to obtain a program package.
第四方面,本申请还提供了一种计算机可读存储介质。所述计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现以下步骤:In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
获取代码打包脚本以及多个静态资源文件,所述代码打包脚本携带有配置文件;执行代码打包脚本,基于所述配置文件中的配置资源属性,分别对各所述静态资源文件各自的静态资源属性进行匹配,得到目标资源文件和基础资源文件,所述目标资源文件为匹配成功的静态资源属性对应的静态资源文件,所述基础资源文件为匹配失败的静态资源属性对应的静态资源文件;将所述目标资源文件上传至服务器,得到所述目标资源文件在所述服务器的在线地址;对包含所述在线地址、所述基础资源文件、所述基础资源文件的本地地址的待打包文件打包处理,得到程序包。Obtain a code packaging script and multiple static resource files, wherein the code packaging script carries a configuration file; execute the code packaging script, and match the static resource attributes of each of the static resource files based on the configuration resource attributes in the configuration file to obtain a target resource file and a basic resource file, wherein the target resource file is a static resource file corresponding to a successfully matched static resource attribute, and the basic resource file is a static resource file corresponding to a failedly matched static resource attribute; upload the target resource file to a server to obtain an online address of the target resource file on the server; package the files to be packaged, which include the online address, the basic resource file, and the local address of the basic resource file, to obtain a program package.
第五方面,本申请还提供了一种计算机程序产品。所述计算机程序产品,包括计算机程序,该计算机程序被处理器执行时实现以下步骤:In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
获取代码打包脚本以及多个静态资源文件,所述代码打包脚本携带有配置文件;执行代码打包脚本,基于所述配置文件中的配置资源属性,分别对各所述静态资源文件各自的静态资源属性进行匹配,得到目标资源文件和基础资源文件,所述目标资源文件为匹配成功的静态资源属性对应的静态资源文件,所述基础资源文件为匹配失败的静态资源属性对应的静态资源文件;将所述目标资源文件上传至服务器,得到所述目标资源文件在所述服务器的在线地址;对包含所述在线地址、所述基础资源文件、所述基础资源文件的本地地址的待打包文件打包处理,得到程序包。Obtain a code packaging script and multiple static resource files, wherein the code packaging script carries a configuration file; execute the code packaging script, and match the static resource attributes of each of the static resource files based on the configuration resource attributes in the configuration file to obtain a target resource file and a basic resource file, wherein the target resource file is a static resource file corresponding to a successfully matched static resource attribute, and the basic resource file is a static resource file corresponding to a failedly matched static resource attribute; upload the target resource file to a server to obtain an online address of the target resource file on the server; package the files to be packaged that include the online address, the basic resource file, and the local address of the basic resource file to obtain a program package.
上述文件处理方法、装置、计算机设备、存储介质和计算机程序产品,获取代码打包脚本以及多个静态资源文件,代码打包脚本携带有配置文件,执行代码打包脚本,基于配置文件中的配置资源属性,分别对各静态资源文件各自的静态资源属性进行匹配,得到目标资源文件和基础资源文件,目标资源文件为匹配成功的静态资源属性对应的静态资源文件,基础资源文件为匹配失败的静态资源属性对应的静态资源文件,采用打包脚本携带的配置文件划分各静态资源文件,便于后续对于不同的静态资源文件进行不同的处理。将目标资源文件上传至服务器,得到目标资源文件在服务器的在线地址,对包含在线地址、基础资源文件、基础资源文件的本地地址的待打包文件打包处理,得到程序包,无需对目标静态资源进行打包,减小了程序包的所占空间,该方法,采用脚本划分各静态资源文件自动化方式,减少了打包消耗时长,提高了打包效率。The above-mentioned file processing method, device, computer equipment, storage medium and computer program product obtain a code packaging script and multiple static resource files. The code packaging script carries a configuration file. The code packaging script is executed. Based on the configuration resource attributes in the configuration file, the static resource attributes of each static resource file are matched respectively to obtain a target resource file and a basic resource file. The target resource file is a static resource file corresponding to the static resource attribute that successfully matches, and the basic resource file is a static resource file corresponding to the static resource attribute that fails to match. The configuration file carried by the packaging script is used to divide each static resource file, which is convenient for subsequent different processing of different static resource files. The target resource file is uploaded to the server, and the online address of the target resource file on the server is obtained. The files to be packaged containing the online address, the basic resource file, and the local address of the basic resource file are packaged and processed to obtain a program package. There is no need to package the target static resources, which reduces the space occupied by the program package. This method uses a script to divide each static resource file in an automated manner, which reduces the packaging time and improves the packaging efficiency.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
图1为一个实施例中文件处理方法的应用环境图;FIG1 is an application environment diagram of a file processing method in one embodiment;
图2为一个实施例中文件处理方法的流程示意图;FIG2 is a schematic diagram of a flow chart of a file processing method in one embodiment;
图3为一个实施例中静态资源文件打包替换方法的流程示意图;FIG3 is a schematic diagram of a process of a static resource file packaging and replacement method in one embodiment;
图4为一个实施例中文件处理装置的结构框图;FIG4 is a structural block diagram of a file processing device in one embodiment;
图5为一个实施例中计算机设备的内部结构图。FIG. 5 is a diagram showing the internal structure of a computer device in one embodiment.
具体实施方式DETAILED DESCRIPTION
为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
本申请实施例提供的文件处理方法,可以应用于如图1所示的应用环境中。其中,终端102通过网络与服务器104进行通信。数据存储系统可以存储服务器104需要处理的数据。数据存储系统可以集成在服务器104上,也可以放在云上或其他网络服务器上。The file processing method provided in the embodiment of the present application can be applied in the application environment shown in FIG1 . In which, the terminal 102 communicates with the server 104 through a network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers.
终端102获取代码打包脚本以及多个静态资源文件,代码打包脚本携带有配置文件,终端102执行代码打包脚本,基于配置文件中的配置资源属性,分别对各静态资源文件各自的静态资源属性进行匹配,得到目标资源文件和基础资源文件,目标资源文件为匹配成功的静态资源属性对应的静态资源文件,基础资源文件为匹配失败的静态资源属性对应的静态资源文件,终端102将目标资源文件上传至服务器104,得到目标资源文件在服务器104的在线地址,终端102对包含在线地址、基础资源文件、基础资源文件的本地地址的待打包文件打包处理,得到程序包。Terminal 102 obtains a code packaging script and multiple static resource files. The code packaging script carries a configuration file. Terminal 102 executes the code packaging script. Based on the configuration resource attributes in the configuration file, the terminal 102 matches the static resource attributes of each static resource file respectively to obtain a target resource file and a basic resource file. The target resource file is a static resource file corresponding to the static resource attribute that is successfully matched, and the basic resource file is a static resource file corresponding to the static resource attribute that fails to match. Terminal 102 uploads the target resource file to server 104 to obtain an online address of the target resource file on server 104. Terminal 102 packages the files to be packaged that include the online address, the basic resource file, and the local address of the basic resource file to obtain a program package.
其中,终端102可以但不限于是各种个人计算机、笔记本电脑、智能手机、平板电脑、物联网设备和便携式可穿戴设备,物联网设备可为智能音箱、智能电视、智能空调、智能车载设备等。便携式可穿戴设备可为智能手表、智能手环、头戴设备等。服务器104可以用独立的服务器或者是多个服务器组成的服务器集群来实现。The terminal 102 may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, IoT devices, and portable wearable devices. The IoT devices may be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. The portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. The server 104 may be implemented as an independent server or a server cluster consisting of multiple servers.
在一个实施例中,如图2所示,提供了一种文件处理方法,以该方法应用于图1中的终端为例进行说明,包括:In one embodiment, as shown in FIG. 2 , a file processing method is provided, which is described by taking the method applied to the terminal in FIG. 1 as an example, including:
S202,获取代码打包脚本以及多个静态资源文件,代码打包脚本携带有配置文件。S202, obtaining a code packaging script and multiple static resource files, where the code packaging script carries a configuration file.
其中,代码打包脚本可以是用在代码打包过程的脚本,代码打包脚本具备文件查询、文件筛选、文件上传、文件打包等文件处理功能。代码打包脚本的对象可以是代码文件和各类资源文件,代码文件包含具体的代码,以及代码分别与各类资源文件各自对应的索引关系。The code packaging script may be a script used in the code packaging process, and the code packaging script has file processing functions such as file query, file screening, file upload, and file packaging. The objects of the code packaging script may be code files and various resource files. The code files contain specific codes, and the index relationships between the codes and various resource files.
其中,配置文件可以是代码打包脚本中对应的操作类型的文件,具体地,通过配置文件中的配置的属性,对资源文件进行相应的文件处理。例如,配置的属性可以是资源文件的文件类型比如JPG格式,依据该资源文件的文件类型从多个资源文件中筛选到多个JPG格式的资源文件。又例如,配置的属性可以是资源文件的文件大小阈值,在多个资源文件中选取文件大小大于该文件大小阈值资源文件。Among them, the configuration file can be a file of the corresponding operation type in the code packaging script. Specifically, the resource file is processed accordingly through the configured attributes in the configuration file. For example, the configured attribute can be the file type of the resource file, such as JPG format, and multiple resource files in JPG format are screened from multiple resource files based on the file type of the resource file. For another example, the configured attribute can be the file size threshold of the resource file, and a resource file whose file size is greater than the file size threshold is selected from multiple resource files.
其中,静态资源文件为在代码开发过程中不随代码逻辑或者数据库状态改变而改变的文件,静态资源文件通常表示预定义好的内容,例如,图片文件、视频文件、字体文件等。为了降低程序包所占存储空间大小,可以将静态资源文件分发到服务器中,在程序包使用时实时从服务器调取静态资源文件。Among them, static resource files are files that do not change with the code logic or database status during the code development process. Static resource files usually represent predefined content, such as image files, video files, font files, etc. In order to reduce the storage space occupied by the program package, static resource files can be distributed to the server, and the static resource files can be retrieved from the server in real time when the program package is used.
其中,字体文件包括ttf、eot、woff、woff2等,用于在网页中展示特定的字体样式。这些字体文件可以确保在不同终端浏览时都能显示所需字体。Among them, font files include ttf, eot, woff, woff2, etc., which are used to display specific font styles on web pages. These font files can ensure that the required fonts can be displayed when browsing on different terminals.
静态资源文件的优化是代码开发和打包过程的重要部分。示例性的,可以先从多个静态资源文件中筛选部分静态资源文件,将部分静态资源文件上传到服务器,由此,减少了本地静态资源的数量、减小了本地静态资源的占用空间,进而减小程序包占用存储空间大小。Optimization of static resource files is an important part of the code development and packaging process. For example, some static resource files can be selected from multiple static resource files and uploaded to the server, thereby reducing the number of local static resources and the space occupied by local static resources, thereby reducing the storage space occupied by the package.
S204,执行代码打包脚本,基于配置文件中的配置资源属性,分别对各静态资源文件各自的静态资源属性进行匹配,得到目标资源文件和基础资源文件,目标资源文件为匹配成功的静态资源属性对应的静态资源文件,基础资源文件为匹配失败的静态资源属性对应的静态资源文件。S204, execute the code packaging script, and match the static resource attributes of each static resource file based on the configuration resource attributes in the configuration file to obtain the target resource file and the basic resource file. The target resource file is the static resource file corresponding to the static resource attribute that is successfully matched, and the basic resource file is the static resource file corresponding to the static resource attribute that fails to match.
其中,配置资源属性表示代码打包脚本中预先配置或者预定以的属性。其中,属性可以描述文件的静态特性,该特性不随时间或者环境变化。The configuration resource attribute refers to the attribute pre-configured or predetermined in the code packaging script. The attribute can describe the static characteristics of the file, which does not change with time or environment.
示例性的,配置资源属性可以是静态资源文件的类型、静态资源文件的大小等。其中,静态资源文件的类型可以包括图片文件、视频文件、字体文件等类型。静态资源文件的大小表示静态资源文件所占存储空间大小。Exemplarily, the configuration resource attribute may be the type of static resource file, the size of the static resource file, etc. The type of static resource file may include image files, video files, font files, etc. The size of the static resource file indicates the size of the storage space occupied by the static resource file.
其中,静态资源属性表示静态资源文件对应的属性,静态资源属性同样可以包括静态资源文件的类型、静态资源文件的大小等。The static resource attributes represent the attributes corresponding to the static resource files, and the static resource attributes may also include the type of the static resource files, the size of the static resource files, and the like.
需说明的,配置资源属性为代码打包脚本中预定义好的资源属性,可以是一个或者多个资源属性,可以根据代码脚本内部逻辑对配置资源属性进行调整,而静态资源属性为各静态资源文件对应的资源属性,这一资源属性一般不会发生变动,可以理解为静态资源文件的固有特性。It should be noted that the configuration resource attributes are predefined resource attributes in the code packaging script, which can be one or more resource attributes. The configuration resource attributes can be adjusted according to the internal logic of the code script, and the static resource attributes are the resource attributes corresponding to each static resource file. This resource attribute generally does not change and can be understood as an inherent characteristic of a static resource file.
其中,目标资源文件为匹配成功的静态资源属性对应的静态资源文件,匹配成功表示静态资源文件是代码打包脚本的提取对象,将匹配成功的静态资源文件提取出来,并发送至服务器,减小了程序包的所占存储空间大小。Among them, the target resource file is the static resource file corresponding to the successfully matched static resource attribute. Successful matching means that the static resource file is the extraction object of the code packaging script. The successfully matched static resource file is extracted and sent to the server, reducing the storage space occupied by the program package.
其中,基础资源文件为匹配失败的静态资源属性对应的静态资源文件,匹配失败表示静态资源文件不是代码打包脚本的提取对象,将匹配失败的静态资源文件和其他文件一起打包,得到程序包。Among them, the basic resource file is the static resource file corresponding to the static resource attribute that failed to match. The matching failure indicates that the static resource file is not the extraction object of the code packaging script. The static resource file that failed to match is packaged together with other files to obtain a program package.
S206,将目标资源文件上传至服务器,得到目标资源文件在服务器的在线地址。S206, uploading the target resource file to the server, and obtaining the online address of the target resource file on the server.
其中,服务器可以是用于存储目标资源文件的服务器,服务器的数量可以是多个,具体地,按照一定服务器筛选规则,从多个服务器中选取目标服务器,将目标资源文件上传到目标服务器,得到目标资源文件在目标服务器的服务器地址。Among them, the server can be a server for storing target resource files, and the number of servers can be multiple. Specifically, according to certain server screening rules, a target server is selected from multiple servers, the target resource file is uploaded to the target server, and the server address of the target resource file on the target server is obtained.
具体地,可以控制代码打包脚本将目标资源文件上传到服务器,其中,代码打包脚本中还携带有资源文件服务器地址,控制代码打包脚本将目标资源文件上传到服务器地址对应的服务器中。Specifically, the code packaging script may be controlled to upload the target resource file to the server, wherein the code packaging script also carries the resource file server address, and the code packaging script is controlled to upload the target resource file to the server corresponding to the server address.
其中,在线地址表示目标资源文件发送到服务器后,服务器返回的目标资源文件的调用地址,在程序包在实际场景中运行时,通过该调用地址在服务器中调用目标资源文件。The online address indicates the calling address of the target resource file returned by the server after the target resource file is sent to the server. When the program package is running in the actual scenario, the target resource file is called in the server through the calling address.
示例性的,程序包在小程序场景中运行时,通过该调用地址可以在服务器中调用预先存储的目标资源文件,解析目标资源文件,得到目标资源,并在对应页面展示目标资源。Exemplarily, when the program package is running in the mini-program scenario, the pre-stored target resource file can be called in the server through the calling address, the target resource file can be parsed, the target resource can be obtained, and the target resource can be displayed on the corresponding page.
S208,对包含在线地址、基础资源文件、基础资源文件的本地地址的待打包文件打包处理,得到程序包。S208, packaging the files to be packaged including the online address, the basic resource file, and the local address of the basic resource file to obtain a program package.
其中,基础资源文件的本地地址表示基础资源在代码文件中的索引地址,在代码文件运行中可以根据该索引地址直接调用基础资源文件。从本地调用资源文件相较于从服务器调用资源文件速度更快。The local address of the basic resource file indicates the index address of the basic resource in the code file. The basic resource file can be directly called according to the index address during the code file operation. Calling resource files from the local is faster than calling resource files from the server.
程序包可以是包含代码文件、静态资源文件等的可执行包,程序包可以是发送至特定服务器,响应于针对程序包对应的界面确认操作,获取并运行程序包。The program package may be an executable package including code files, static resource files, etc. The program package may be sent to a specific server, and in response to an interface confirmation operation corresponding to the program package, the program package may be obtained and run.
示例性的,在小程序使用场景,响应于用户针对小程序点击操作,获取并运行小程序对应的程序包,程序包在运行过程中,从用户终端本地调用基础资源文件,从服务器调用目标资源文件。Exemplarily, in the mini-program usage scenario, in response to a user clicking on the mini-program, the program package corresponding to the mini-program is obtained and run. During the running process, the program package calls the basic resource files from the user terminal locally and calls the target resource files from the server.
上述文件处理方法中,获取代码打包脚本以及多个静态资源文件,代码打包脚本携带有配置文件,执行代码打包脚本,基于配置文件中的配置资源属性,分别对各静态资源文件各自的静态资源属性进行匹配,得到目标资源文件和基础资源文件,目标资源文件为匹配成功的静态资源属性对应的静态资源文件,基础资源文件为匹配失败的静态资源属性对应的静态资源文件,采用打包脚本携带的配置文件划分各静态资源文件,便于后续对于不同的静态资源文件进行不同的处理。将目标资源文件上传至服务器,得到目标资源文件在服务器的在线地址,对包含在线地址、基础资源文件、基础资源文件的本地地址的待打包文件打包处理,得到程序包,无需对目标静态资源进行打包,减小了程序包的所占空间,该方法,采用脚本划分各静态资源文件自动化方式,减少了打包消耗时长,提高了打包效率。In the above file processing method, a code packaging script and multiple static resource files are obtained. The code packaging script carries a configuration file. The code packaging script is executed. Based on the configuration resource attributes in the configuration file, the static resource attributes of each static resource file are matched respectively to obtain a target resource file and a basic resource file. The target resource file is a static resource file corresponding to the static resource attribute that is successfully matched, and the basic resource file is a static resource file corresponding to the static resource attribute that fails to match. The configuration file carried by the packaging script is used to divide each static resource file, which is convenient for subsequent different processing of different static resource files. The target resource file is uploaded to the server, and the online address of the target resource file on the server is obtained. The files to be packaged that include the online address, the basic resource file, and the local address of the basic resource file are packaged and processed to obtain a program package. There is no need to package the target static resources, which reduces the space occupied by the program package. This method uses a script to divide each static resource file in an automated manner, which reduces the time consumed by packaging and improves the packaging efficiency.
在一个实施例中,配置资源属性包括资源类型条件和资源大小条件,静态资源属性包括静态资源类型和静态资源大小,执行代码打包脚本,基于配置文件中的配置资源属性,分别对各静态资源文件各自的静态资源属性进行匹配,得到目标资源文件和基础资源文件,包括:In one embodiment, the configuration resource attributes include resource type conditions and resource size conditions, the static resource attributes include static resource types and static resource sizes, and the code packaging script is executed to match the static resource attributes of each static resource file based on the configuration resource attributes in the configuration file to obtain the target resource file and the basic resource file, including:
执行代码打包脚本,基于配置文件中的资源类型条件,分别对各静态资源文件各自的静态资源类型进行匹配,得到资源类型条件分别与各静态资源文件之间的类型匹配结果,Execute the code packaging script, match the static resource type of each static resource file based on the resource type conditions in the configuration file, and obtain the type matching results between the resource type conditions and each static resource file.
基于配置文件中的资源大小条件,分别对各静态资源文件各自的静态资源大小进行匹配,得到资源大小条件分别与各静态资源文件之间的大小匹配结果;Based on the resource size conditions in the configuration file, the static resource sizes of the static resource files are matched respectively to obtain size matching results between the resource size conditions and the static resource files;
根据类型匹配结果和大小匹配结果,将各静态资源文件划分为目标资源文件和基础资源文件。According to the type matching results and the size matching results, each static resource file is divided into a target resource file and a basic resource file.
其中,代码打包脚本可以是用在代码打包过程的脚本,代码打包脚本具备文件查询、文件筛选、文件上传、文件打包等文件处理功能。代码打包脚本的对象可以是代码文件和各类资源文件,代码文件包含具体的代码,以及代码分别与各类资源文件各自对应的索引关系。The code packaging script may be a script used in the code packaging process, and the code packaging script has file processing functions such as file query, file screening, file upload, and file packaging. The objects of the code packaging script may be code files and various resource files. The code files contain specific codes, and the index relationships between the codes and various resource files.
其中,配置文件可以是代码打包脚本中对应的操作类型的文件,具体地,通过配置文件中的配置的属性,对资源文件进行相应的文件处理。The configuration file may be a file of a corresponding operation type in the code packaging script. Specifically, the resource file is processed accordingly through the configured attributes in the configuration file.
其中,配置资源属性表示代码打包脚本中预先配置或者预定以的属性。其中,属性可以描述文件的静态特性,该特性不随时间或者环境变化。The configuration resource attribute refers to the attribute pre-configured or predetermined in the code packaging script. The attribute can describe the static characteristics of the file, which does not change with time or environment.
具体的,配置资源属性包括资源类型条件和资源大小条件,资源类型条件可以表示预先配置或者预先定义的文件类型,例如,JPG类型文件、PNG类型文件、WOFF类型文件等其中至少一种。资源大小条件可以是表示预先配置或者预先定义的文件大小,例如,单个文件大小大于50~100k。Specifically, the configuration resource attributes include a resource type condition and a resource size condition. The resource type condition may represent a pre-configured or pre-defined file type, for example, at least one of a JPG type file, a PNG type file, and a WOFF type file. The resource size condition may represent a pre-configured or pre-defined file size, for example, a single file size is greater than 50-100k.
其中,静态资源属性表示静态资源文件对应的属性,静态资源属性同样可以包括静态资源文件的类型、静态资源文件的大小等。The static resource attributes represent the attributes corresponding to the static resource files, and the static resource attributes may also include the type of the static resource files, the size of the static resource files, and the like.
具体的,静态资源属性包括静态资源类型和静态资源大小,静态资源类型表示静态资源文件的文件类型,例如,JPG、PNG、WOFF等,静态资源大小表示静态资源文件的占用空间大小。Specifically, the static resource attributes include static resource type and static resource size. The static resource type indicates the file type of the static resource file, such as JPG, PNG, WOFF, etc. The static resource size indicates the size of the space occupied by the static resource file.
其中,类型匹配结果描述的是资源类型条件分别与各静态资源文件之间的匹配结果,匹配结果包括匹配成功和匹配失败,匹配成功代表静态资源文件的静态资源类型和资源类型条件对应的资源类型相同或者相近。例如,资源类型条件可以是JPG类型,可以各静态资源类型为JPG类型的静态资源文件与该资源类型条件匹配成功,其他类型静态资源文件与该资源类型条件匹配失败。还可是JPG类型和PNG类型的静态资源文件均与该资源类型条件匹配成功,其他类型静态资源文件与该资源类型条件匹配失败。PNG类型和JPG类型为相似类型。Among them, the type matching result describes the matching results between the resource type condition and each static resource file respectively. The matching results include successful matching and failed matching. Successful matching means that the static resource type of the static resource file is the same or similar to the resource type corresponding to the resource type condition. For example, the resource type condition can be a JPG type, and each static resource file of the JPG type can successfully match the resource type condition, and other types of static resource files can fail to match the resource type condition. It can also be that both JPG type and PNG type static resource files successfully match the resource type condition, and other types of static resource files fail to match the resource type condition. PNG type and JPG type are similar types.
其中,大小匹配结果描述的是资源大小条件分别与各静态资源文件之间的匹配结果,匹配结果包括匹配成功和匹配失败,匹配成功代表静态资源文件的静态资源大小在资源大小条件对应的数值范围内。例如,资源大小条件可以是单个文件大于80kb,当静态资源文件的静态资源大小,即,所占存储空间大小大于80kb,则认为该静态资源文件与资源大小条件匹配成功,反之则匹配失败。Among them, the size matching result describes the matching result between the resource size condition and each static resource file. The matching result includes a successful match and a failed match. A successful match means that the static resource size of the static resource file is within the numerical range corresponding to the resource size condition. For example, the resource size condition can be that a single file is larger than 80kb. When the static resource size of a static resource file, that is, the size of the storage space occupied, is larger than 80kb, it is considered that the static resource file successfully matches the resource size condition, otherwise the match fails.
其中,类型匹配结果包括匹配成功和匹配失败,大小匹配结果包括匹配成功和匹配失败,可以理解的针对于一个静态资源文件,该静态资源文件对应有类型匹配结果和大小匹配结果。Among them, the type matching result includes a successful match and a failed match, and the size matching result includes a successful match and a failed match. It can be understood that for a static resource file, the static resource file corresponds to a type matching result and a size matching result.
具体地,可以根据静态资源对应的类型匹配结果和大小匹配结果,将各静态资源文件划分为目标资源文件或者基础资源文件。Specifically, each static resource file may be divided into a target resource file or a basic resource file according to a type matching result and a size matching result corresponding to the static resource.
其中,目标资源文件为即将存储在其他位置,不占用程序包空间的资源文件,例如,将目标资源文件发送至服务器。基础资源文件为程序包中的资源文件。The target resource file is a resource file that will be stored in other locations and does not occupy the space of the program package. For example, the target resource file is sent to the server. The basic resource file is a resource file in the program package.
可以理解的,目标资源文件对应的类型匹配结果和大小匹配结果可以是均为成功,此时,基础资源文件对应的类型匹配结果和大小匹配结果中至少一个匹配结果为匹配失败。It can be understood that the type matching result and the size matching result corresponding to the target resource file may both be successful. In this case, at least one of the type matching result and the size matching result corresponding to the basic resource file is a matching failure.
目标资源文件对应的类型匹配结果和大小匹配结果可以是至少一个为匹配成功,此时,基础资源文件对应的类型匹配结果和大小匹配结果均为匹配失败。At least one of the type matching result and the size matching result corresponding to the target resource file may be a successful match. In this case, both the type matching result and the size matching result corresponding to the basic resource file are failed matches.
本实施例中,通过执行代码打包脚本,基于配置文件中的资源类型条件,分别对各静态资源文件各自的静态资源类型进行匹配,得到资源类型条件分别与各静态资源文件之间的类型匹配结果,基于配置文件中的资源大小条件,分别对各静态资源文件各自的静态资源大小进行匹配,得到资源大小条件分别与各静态资源文件之间的大小匹配结果,根据类型匹配结果和大小匹配结果,将各静态资源文件划分为目标资源文件和基础资源文件,准确划分各静态资源文件,便于后续分别对目标资源文件和基础资源文件进行不同处理,为减少打包消耗时长,提高打包效率提供依据。In this embodiment, by executing the code packaging script, based on the resource type conditions in the configuration file, the static resource types of each static resource file are matched respectively, and the type matching results between the resource type conditions and each static resource file are obtained; based on the resource size conditions in the configuration file, the static resource sizes of each static resource file are matched respectively, and the size matching results between the resource size conditions and each static resource file are obtained; according to the type matching results and the size matching results, each static resource file is divided into a target resource file and a basic resource file, and each static resource file is accurately divided, which facilitates the subsequent different processing of the target resource file and the basic resource file, and provides a basis for reducing the packaging time and improving the packaging efficiency.
在一个实施例中,根据类型匹配结果和大小匹配结果,将各静态资源文件划分为目标资源文件和基础资源文件,包括:按照各类型匹配结果,筛选各静态资源文件中资源类型匹配成功的静态资源文件,按照各大小匹配结果,筛选各静态资源文件中资源大小匹配成功的静态资源文件,合并资源类型匹配成功的静态资源文件和资源大小匹配成功的静态资源文件,得到目标资源文件,并将除目标资源文件以外各静态资源文件确定为基础资源文件。In one embodiment, each static resource file is divided into a target resource file and a basic resource file according to the type matching result and the size matching result, including: screening the static resource files whose resource types are successfully matched in each static resource file according to each type matching result, screening the static resource files whose resource sizes are successfully matched in each static resource file according to each size matching result, merging the static resource files whose resource types are successfully matched and the static resource files whose resource sizes are successfully matched to obtain the target resource file, and determining each static resource file except the target resource file as a basic resource file.
其中,类型匹配结果包括匹配成功和匹配失败,大小匹配结果包括匹配成功和匹配失败,可以理解的针对于一个静态资源文件,该静态资源文件对应有类型匹配结果和大小匹配结果。Among them, the type matching result includes a successful match and a failed match, and the size matching result includes a successful match and a failed match. It can be understood that for a static resource file, the static resource file corresponds to a type matching result and a size matching result.
具体地,可以按照各类型匹配结果,筛选各静态资源文件中资源类型匹配成功的静态资源文件。资源类型匹配成功的静态资源文件的数量可以为多个。Specifically, according to the matching results of each type, the static resource files whose resource types are successfully matched among the static resource files can be screened. The number of static resource files whose resource types are successfully matched can be multiple.
具体地,可以按照各大小匹配结果,筛选各静态资源文件中资源大小匹配成功的静态资源文件。资源大小匹配成功的静态资源文件的数量可以为多个。Specifically, according to the size matching results, the static resource files with successful resource size matching among the static resource files can be screened. The number of static resource files with successful resource size matching can be multiple.
资源类型匹配成功的静态资源文件可以称为第一静态资源文件,资源大小匹配成功的静态资源文件可以称为第二静态资源文件。The static resource file whose resource type matches successfully can be called a first static resource file, and the static resource file whose resource size matches successfully can be called a second static resource file.
其中,合并资源类型匹配成功的静态资源文件和资源大小匹配成功的静态资源文件,即合并第一静态资源文件和第二静态资源文件。合并代表将表示将多个第一静态资源文件、多个第二静态资源文件合并到一个集合,并筛除表示相同静态资源文件第一静态资源文件与第二静态资源文件中任意一个。示例性的,第一静态资源文件包括a、b、c,第二静态资源文件包括b、d,合并先将a、b、c,以及b、d合并,得到a、b、b、c、d,再筛除两个b中任意一个,得到a、b、c、d。目标资源文件包括a、b、c、d。Among them, merging the static resource files that successfully match the resource type and the static resource files that successfully match the resource size, that is, merging the first static resource file and the second static resource file. The merging representation will indicate that multiple first static resource files and multiple second static resource files are merged into a set, and any one of the first static resource files and the second static resource files representing the same static resource file is filtered out. Exemplarily, the first static resource file includes a, b, c, and the second static resource file includes b and d. The merging first merges a, b, c, and b, d to obtain a, b, b, c, d, and then any one of the two b is filtered out to obtain a, b, c, d. The target resource files include a, b, c, d.
其中,基础资源文件表示程序包中的资源文件。目标资源文件表示不在程序包中的资源文件。需说明的,基础资源文件的本地索引地址存储于程序包中的代码中,而目标资源文件对应的索引地址同样存储于程序包中的代码中。在代码运行时根据索引地址到索引地址对应的地址中调用资源文件。Among them, the basic resource file refers to the resource file in the program package. The target resource file refers to the resource file that is not in the program package. It should be noted that the local index address of the basic resource file is stored in the code in the program package, and the index address corresponding to the target resource file is also stored in the code in the program package. When the code is running, the resource file is called according to the index address to the address corresponding to the index address.
本实施例中,按照各类型匹配结果,筛选各静态资源文件中资源类型匹配成功的静态资源文件,按照各大小匹配结果,筛选各静态资源文件中资源大小匹配成功的静态资源文件,合并资源类型匹配成功的静态资源文件和资源大小匹配成功的静态资源文件,得到目标资源文件,并将除目标资源文件以外各静态资源文件确定为基础资源文件,准确划分各静态资源文件,便于后续分别对目标资源文件和基础资源文件进行不同处理,为减少打包消耗时长,提高打包效率提供依据。In this embodiment, according to the results of each type matching, the static resource files whose resource types are successfully matched in each static resource file are screened, and according to the results of each size matching, the static resource files whose resource sizes are successfully matched in each static resource file are screened, and the static resource files whose resource types are successfully matched and the static resource files whose resource sizes are successfully matched are merged to obtain the target resource file, and each static resource file except the target resource file is determined as a basic resource file, and each static resource file is accurately divided, so as to facilitate the subsequent different processing of the target resource file and the basic resource file, respectively, and provide a basis for reducing the packaging time and improving the packaging efficiency.
在一个实施例中,将目标资源文件上传至服务器,得到目标资源文件在服务器的在线地址,包括:确定与目标资源文件的静态资源属性匹配的多个候选服务器,按照各候选服务器各自的负载特征,在各候选服务器中选取目标服务器,将目标资源文件上传至目标服务器,接收目标服务器发送的目标资源文件在目标服务器的在线地址。In one embodiment, the target resource file is uploaded to the server to obtain the online address of the target resource file on the server, including: determining multiple candidate servers that match the static resource attributes of the target resource file, selecting a target server from each candidate server according to the load characteristics of each candidate server, uploading the target resource file to the target server, and receiving the online address of the target resource file on the target server sent by the target server.
其中,候选服务器可以是用于存储各类静态资源的服务器。可以将目标资源存储到不同候选服务器中,再从候选服务器中调用目标资源服务器。为了便于提高服务器接收和发送目标资源文件的效率,可以从多个候选服务器中筛选出特定的服务器,将目标资源文件发送至特定的服务器。The candidate server may be a server for storing various types of static resources. The target resource may be stored in different candidate servers, and then the target resource server may be called from the candidate server. In order to improve the efficiency of the server receiving and sending the target resource file, a specific server may be selected from multiple candidate servers, and the target resource file may be sent to the specific server.
其中,目标服务器可以是根据各候选服务器各自的负载特征,从各候选服务器中选取的一个服务器作为目标服务器。The target server may be a server selected from the candidate servers according to the load characteristics of the candidate servers.
其中,负载特征表征服务器工作负载情况,负载特征包括:CPU负载、内存负载、IO负载。The load characteristics represent the server workload, and the load characteristics include: CPU load, memory load, and IO load.
具体地,针对于一个候选服务器的CPU负载、内存负载、IO负载,按照一定规则,分别对CPU负载、内存负载、IO负载进行打分,得到该候选服务器的负载特征值,再按照各候选服务器各自的负载特征值,再各候选服务器中选取负载特征值最大的服务器作为目标服务器。对候选服务器的CPU负载、内存负载、IO负载分别进行评分,得到CPU负载评分、内存负载评分、IO负载评分,再对CPU负载评分、内存负载评分、IO负载评分求均值,得到候选服务器的负载特征值。候选服务器的负载特征值越高代表候选服务器的越接近与空闲状态,接收和发送目标资源文件的速度更快。Specifically, for the CPU load, memory load, and IO load of a candidate server, the CPU load, memory load, and IO load are scored according to certain rules to obtain the load characteristic value of the candidate server, and then according to the load characteristic values of each candidate server, the server with the largest load characteristic value is selected as the target server. The CPU load, memory load, and IO load of the candidate server are scored respectively to obtain the CPU load score, memory load score, and IO load score, and then the CPU load score, memory load score, and IO load score are averaged to obtain the load characteristic value of the candidate server. The higher the load characteristic value of the candidate server, the closer the candidate server is to the idle state, and the faster it is to receive and send the target resource file.
其中,确定目标服务器后,将目标资源文件上传到目标服务器,接收目标服务器发送的目标资源文件在目标服务器的在线地址。在线地址表示目标资源文件在服务器中的存储地址。在程序包运行时,可以调用该存储地址,调取到该目标资源文件。After the target server is determined, the target resource file is uploaded to the target server, and the online address of the target resource file on the target server sent by the target server is received. The online address represents the storage address of the target resource file in the server. When the program package is running, the storage address can be called to retrieve the target resource file.
本实施例中,确定与目标资源文件的静态资源属性匹配的多个候选服务器,按照各候选服务器各自的负载特征,在各候选服务器中选取目标服务器,将目标资源文件上传至目标服务器,接收目标服务器发送的目标资源文件在目标服务器的在线地址,选取了接收和发送目标资源文件速度更快的目标服务器,提高了目标资源文件的发送以及接收效率。In this embodiment, multiple candidate servers that match the static resource attributes of the target resource file are determined, and a target server is selected from each candidate server according to the load characteristics of each candidate server. The target resource file is uploaded to the target server, and the online address of the target resource file on the target server sent by the target server is received. A target server that is faster in receiving and sending the target resource file is selected, thereby improving the sending and receiving efficiency of the target resource file.
在一个实施例中,对包含在线地址、基础资源文件、基础资源文件的本地地址的待打包文件打包处理,得到程序包,包括:在资源文件库中提取与基础资源文件存在分辨率关联关系的候选资源文件,确定基础资源文件的基础本地地址,以及候选资源文件的候选本地地址,对包含在线地址、基础本地地址、候选本地地址、基础资源文件、候选资源文件的待打包文件打包处理,得到程序包。In one embodiment, the files to be packaged, which include an online address, a basic resource file, and a local address of the basic resource file, are packaged to obtain a program package, including: extracting candidate resource files that have a resolution association relationship with the basic resource file from a resource file library, determining a basic local address of the basic resource file and a candidate local address of the candidate resource file, and packaging the files to be packaged, which include an online address, a basic local address, a candidate local address, a basic resource file, and a candidate resource file, to obtain a program package.
其中,资源文件库可以是存储各类资源文件的数据库,该数据库中存储了各类资源文件,对于特定的资源文件,该数据库中还存有与该资源文件存在分辨率关联关系的候选资源文件。数据库的类型在此不做限定。The resource file library may be a database storing various resource files, wherein the database stores various resource files, and for a specific resource file, the database also stores candidate resource files having a resolution association relationship with the resource file. The type of database is not limited here.
其中,分辨率关联关系表示对于表征同一资源内容的多个资源文件之间的关系。具备分辨率关联关系的多个资源文件之间区别在于资源文件的分辨率不同,以及资源文件占用的空间大小不同。其中,基础资源文件分别与各候选资源文件之间的区别在于资源文件的分辨率不同,以及资源文件占用的空间大小不同。The resolution association relationship indicates the relationship between multiple resource files representing the same resource content. The difference between multiple resource files with a resolution association relationship is that the resolutions of the resource files are different, and the sizes of space occupied by the resource files are different. The difference between the basic resource file and each candidate resource file is that the resolutions of the resource files are different, and the sizes of space occupied by the resource files are different.
具体地,在资源文件库中提取与基础资源文件存在分辨率关联关系的候选资源文件,可以将基础资源文件和候选资源文件同时进行打包,得到程序包,并在程序包运行时提供多种分辨率显示的方案,为用户提供全面的参考。Specifically, candidate resource files that have a resolution association relationship with basic resource files are extracted from the resource file library, and the basic resource files and candidate resource files can be packaged at the same time to obtain a program package, and multiple resolution display solutions are provided when the program package is running, providing users with a comprehensive reference.
其中,基础本地地址表示在基础资源文件在本地的调用地址,可以根据该调用地址调用基础资源文件,并展示该基础资源文件对应的基础资源。同样的,候选本地地址表示在候选资源文件在本地的调用地址,可以根据该调用地址调用候选资源文件,并展示该候选资源文件对应的候选资源。The basic local address represents the local calling address of the basic resource file, and the basic resource file can be called according to the calling address, and the basic resource corresponding to the basic resource file is displayed. Similarly, the candidate local address represents the local calling address of the candidate resource file, and the candidate resource file can be called according to the calling address, and the candidate resource corresponding to the candidate resource file is displayed.
其中,候选资源文件的分辨率、占用的空间大小可以均大于基础资源文件,以此,得到的程序包中包含更清晰的基础资源文件,提高了展示的精度。候选资源文件的分辨率、占用的空间大小可以均小于基础资源文件,以此,得到的程序包中包含较模糊的基础资源文件,可以适用于不同显示精度要求的界面,直接通过调用不同分辨率的候选资源文件,而不需要对基础资源文件进行模糊处理,节省了对基础资源文件进行模糊处理所消耗的时间,提高了文件处理效率。The resolution and space occupied by the candidate resource files can be larger than the basic resource files, so that the obtained program package contains clearer basic resource files, which improves the display accuracy. The resolution and space occupied by the candidate resource files can be smaller than the basic resource files, so that the obtained program package contains more blurred basic resource files, which can be applied to interfaces with different display accuracy requirements. By directly calling candidate resource files of different resolutions, there is no need to blur the basic resource files, which saves the time consumed by blurring the basic resource files and improves the file processing efficiency.
本实施例中,在资源文件库中提取与基础资源文件存在分辨率关联关系的候选资源文件,确定基础资源文件的基础本地地址,以及候选资源文件的候选本地地址,对包含在线地址、基础本地地址、候选本地地址、基础资源文件、候选资源文件的待打包文件打包处理,得到程序包,程序包中包含不同分辨率大小的候选资源文件,为展示不同分辨率的资源文件提供依据,提高了展示效果。In this embodiment, candidate resource files that have a resolution association relationship with the basic resource files are extracted from the resource file library, the basic local address of the basic resource file and the candidate local addresses of the candidate resource files are determined, and the files to be packaged including the online address, the basic local address, the candidate local address, the basic resource file, and the candidate resource file are packaged to obtain a program package, which includes candidate resource files of different resolution sizes, thereby providing a basis for displaying resource files with different resolutions and improving the display effect.
在一个实施例中,获取多个静态资源文件,包括:获取待打包文件中的项目代码,扫描项目代码,得到项目代码对应的多个备选资源文件,对各备选资源文件进行文件类优化处理,得到多个静态资源文件,对包含在线地址、基础资源文件、基础资源文件的本地地址的待打包文件打包处理,得到程序包,包括:对包含在线地址、基础资源文件的本地地址的项目代码,以及基础资源文件打包处理,得到程序包。In one embodiment, multiple static resource files are obtained, including: obtaining project codes in the files to be packaged, scanning the project codes to obtain multiple candidate resource files corresponding to the project codes, performing file class optimization processing on each candidate resource file to obtain multiple static resource files, and packaging the files to be packaged including online addresses, basic resource files, and local addresses of basic resource files to obtain a program package, including: packaging the project codes including online addresses, local addresses of basic resource files, and basic resource files to obtain a program package.
其中,待打包文件表示未进行打包的文件,待打包文件中包括项目代码、静态资源文件。具体地,在待打包文件中的多个静态资源文件中选取部分静态资源文件作为目标资源文件,留下的静态资源文件为基础资源文件,再对包含基础资源文件的待打包文件打包处理,得到程序包,以此,通过减少待打包文件中包含的静态资源文件数,减小程序包的大小,使得程序包的大小符合存储空间的要求,例如,在小程序场景中,程序包对应的存储空间要求文程序包大小小于2~4MB。Among them, the files to be packaged refer to files that have not been packaged, and the files to be packaged include project codes and static resource files. Specifically, some static resource files are selected from multiple static resource files in the files to be packaged as target resource files, and the remaining static resource files are used as basic resource files. Then, the files to be packaged containing the basic resource files are packaged and processed to obtain a program package. In this way, by reducing the number of static resource files included in the files to be packaged, the size of the program package is reduced, so that the size of the program package meets the storage space requirements. For example, in the mini program scenario, the storage space corresponding to the program package requires that the program package size is less than 2~4MB.
其中,项目代码可以指的是任何特定项目所使用的编程代码。一个项目可能包含多种编程语言、库、框架和工具,并且这些代码可能分布在多个文件、目录和模块中。项目代码中包含各类资源文件的调用功能地址,项目代码包含静态资源文件的调用地址。Among them, project code can refer to the programming code used by any specific project. A project may contain multiple programming languages, libraries, frameworks, and tools, and these codes may be distributed in multiple files, directories, and modules. The project code contains the calling function addresses of various resource files, and the project code contains the calling addresses of static resource files.
具体地,扫描项目代码中各调用地址,得到项目代码对应的多个备选资源文件。Specifically, each calling address in the project code is scanned to obtain a plurality of candidate resource files corresponding to the project code.
其中,备选资源文件表示与项目代码存在直接调用关系的资源文件。Among them, the alternative resource file refers to the resource file that has a direct calling relationship with the project code.
为了提高程序包运行性能和用户体验,对各备选资源文件进行文件类优化处理,得到各文件类优化处理后的备选资源文件,即各静态资源文件。In order to improve the running performance of the program package and the user experience, each candidate resource file is subjected to file class optimization processing to obtain the candidate resource files after each file class optimization processing, that is, each static resource file.
其中,文件类优化处理包括对备选资源文件压缩处理、对备选资源文件格式优化处理等。示例性的,对备选资源文件压缩处理可以是压缩资源文件中的注释、空白、未使用的CSS选择器等。对备选资源文件格式优化处理可以是使用格式转化工具转化备选资源文件的格式,以减小文件大小。The file type optimization processing includes compression processing of candidate resource files, optimization processing of the format of candidate resource files, etc. Exemplarily, compression processing of candidate resource files may be to compress comments, blanks, unused CSS selectors, etc. in the resource files. Optimization processing of the format of candidate resource files may be to convert the format of the candidate resource files using a format conversion tool to reduce the file size.
具体地,得到多个静态资源文件后,通过以上文件处理方法,将多个静态资源文件划分为目标资源文件和基础资源文件,将目标资源文件发送至服务器,得到目标资源文件的在线地址,此时的待打包文件中包括项目代码和基础资源文件,而项目代码中存有基础资源文件的本地地址,目标资源文件的在线地址。通过对项目代码和基础资源文件打包处理,得到程序包。Specifically, after obtaining multiple static resource files, the multiple static resource files are divided into target resource files and basic resource files through the above file processing method, and the target resource files are sent to the server to obtain the online address of the target resource files. At this time, the files to be packaged include project codes and basic resource files, and the local address of the basic resource files and the online address of the target resource files are stored in the project code. By packaging the project code and the basic resource files, a program package is obtained.
本实施例中,获取待打包文件中的项目代码,扫描项目代码,得到项目代码对应的多个备选资源文件,对各备选资源文件进行文件类优化处理,得到多个静态资源文件,并对包含在线地址、基础资源文件的本地地址的项目代码,以及基础资源文件打包处理,得到程序包,对个备选资源文件进行文件类优化处理,缩减资源文件的所占空间大小,尽可能减小程序包的所占空间大小,使得程序包的大小满足存储空间大小要求。In this embodiment, the project code in the file to be packaged is obtained, the project code is scanned, and multiple candidate resource files corresponding to the project code are obtained. File class optimization processing is performed on each candidate resource file to obtain multiple static resource files, and the project code containing the online address, the local address of the basic resource file, and the basic resource file are packaged to obtain a program package, and file class optimization processing is performed on each candidate resource file to reduce the size of the space occupied by the resource file, and the size of the space occupied by the program package is reduced as much as possible, so that the size of the program package meets the storage space size requirement.
需说明的,微信小程序为了运行效率、存储成本等方面的考虑,在上传版本到服务器时会有体积要求,目前要求上传的代码体积不能超过2M。而目前的获客类活动项目,会有大量的资源文件,例如,图片、视频等用于展示,这些资源文件仍然受上传代码体积限制管控。现在对于这种资源文件一般是开发阶段使用本地资源文件,当上传正式版本时换为使用线上地址的资源文件,开发人员需要手动做这一步替换使用文件的路径的操作。It should be noted that for the sake of operational efficiency and storage costs, WeChat Mini Programs have size requirements when uploading versions to the server. Currently, the uploaded code size cannot exceed 2M. Current customer acquisition activity projects have a large number of resource files, such as pictures and videos for display. These resource files are still subject to the upload code size limit. Currently, local resource files are generally used in the development phase for such resource files. When uploading the official version, they are replaced with resource files using online addresses. Developers need to manually perform this step to replace the path of the file used.
这种手工操作带来一些问题:比如1、上传正式版本时需要手动检查,费时费力;2、项目维护成本较高,换新的资源文件较为费力;3、项目组新添加人员时,新开发人员熟悉项目的成本较高。This manual operation brings some problems: for example, 1. Manual checking is required when uploading the official version, which is time-consuming and laborious; 2. The project maintenance cost is high, and it is more laborious to replace new resource files; 3. When new people are added to the project team, the cost for new developers to familiarize themselves with the project is high.
在一个实施例中,如图3所示的静态资源文件打包替换方法的流程示意图,静态资源文件打包替换方法,包括:In one embodiment, as shown in FIG. 3 , the static resource file packaging and replacement method is a flowchart of the static resource file packaging and replacement method, which includes:
S302,获取代码打包脚本,代码打包脚本携带有配置文件。S302, obtaining a code packaging script, where the code packaging script carries a configuration file.
其中,获取代码打包脚本、执行该脚本,以及对程序包进行调整的处理工具可以是微信小程序IDE,微信小程序IDE是为了帮助开发者简单和高效地开发和调试微信小程序的工具。Among them, the processing tool for obtaining the code packaging script, executing the script, and adjusting the program package can be the WeChat Mini Program IDE. The WeChat Mini Program IDE is a tool to help developers develop and debug WeChat Mini Programs simply and efficiently.
其中,代码打包脚本是通过webpack工具编写的脚本,webpack是代码编译工具,有入口、出口、loader和插件。webpack是一个用于现代JavaScript应用程序的静态模块打包工具。Among them, the code packaging script is a script written by the webpack tool. Webpack is a code compilation tool with entry, exit, loader and plug-in. Webpack is a static module packaging tool for modern JavaScript applications.
S304,获取待打包文件中的项目代码。S304, obtaining the project code in the file to be packaged.
S306,扫描项目代码,得到项目代码对应的多个备选资源文件。S306, scanning the project code to obtain multiple candidate resource files corresponding to the project code.
其中,代码打包脚本具备代码扫描功能。Among them, the code packaging script has the function of code scanning.
S308,对各备选资源文件进行文件类优化处理,得到多个静态资源文件。S308, performing file type optimization processing on each candidate resource file to obtain multiple static resource files.
S310,执行代码打包脚本,基于配置文件中的资源类型条件,分别对各静态资源文件各自的静态资源类型进行匹配,得到资源类型条件分别与各静态资源文件之间的类型匹配结果。S310, executing the code packaging script, matching the static resource type of each static resource file based on the resource type condition in the configuration file, and obtaining the type matching results between the resource type condition and each static resource file.
其中,配置资源属性包括资源类型条件和资源大小条件。静态资源属性包括静态资源类型和静态资源大小。The configuration resource attributes include resource type conditions and resource size conditions. The static resource attributes include static resource type and static resource size.
示例性的,配置文件中配置有打包脚本所需数据,具体包括:1、需要识别的静态资源文件的类型条件,例如,jpg、png、woff等;2、静态资源文件的大小条件,例如静态资源文件大小小于100KB;3、目标资源文件对应的服务器登录账号、密码、目标资源文件在服务器中的存放路径。Exemplarily, the configuration file is configured with the data required for the packaging script, including: 1. The type conditions of the static resource files that need to be identified, for example, jpg, png, woff, etc.; 2. The size conditions of the static resource files, for example, the size of the static resource files is less than 100KB; 3. The server login account and password corresponding to the target resource file, and the storage path of the target resource file in the server.
S312,基于配置文件中的资源大小条件,分别对各静态资源文件各自的静态资源大小进行匹配,得到资源大小条件分别与各静态资源文件之间的大小匹配结果。S312, based on the resource size condition in the configuration file, respectively match the static resource size of each static resource file to obtain size matching results between the resource size condition and each static resource file.
S314,按照各类型匹配结果,筛选各静态资源文件中资源类型匹配成功的静态资源文件。S314, according to the matching results of each type, filter the static resource files whose resource types have successfully matched among the static resource files.
S316,按照各大小匹配结果,筛选各静态资源文件中资源大小匹配成功的静态资源文件。S316, according to the size matching results, filter the static resource files whose resource sizes have successfully matched among the static resource files.
S318,合并资源类型匹配成功的静态资源文件和资源大小匹配成功的静态资源文件,得到目标资源文件和基础资源文件。S318, merging the static resource files whose resource types are successfully matched and the static resource files whose resource sizes are successfully matched, to obtain the target resource files and the basic resource files.
其中,将除目标资源文件以外各静态资源文件确定为基础资源文件。Among them, each static resource file except the target resource file is determined as a basic resource file.
其中,目标资源文件为匹配成功的静态资源属性对应的静态资源文件,基础资源文件为匹配失败的静态资源属性对应的静态资源文件。The target resource file is a static resource file corresponding to a successfully matched static resource attribute, and the basic resource file is a static resource file corresponding to a failedly matched static resource attribute.
S320,确定与目标资源文件的静态资源属性匹配的多个候选服务器。S320: Determine multiple candidate servers that match the static resource attributes of the target resource file.
S322,按照各候选服务器各自的负载特征,在各候选服务器中选取目标服务器。S322: Select a target server from the candidate servers according to the load characteristics of the candidate servers.
S324,将目标资源文件上传至目标服务器,接收目标服务器发送的目标资源文件在目标服务器的在线地址。S324, uploading the target resource file to the target server, and receiving the online address of the target resource file on the target server sent by the target server.
S326,在资源文件库中提取与基础资源文件存在分辨率关联关系的候选资源文件。S326, extracting candidate resource files having a resolution association relationship with the basic resource file from the resource file library.
S328,确定基础资源文件的基础本地地址,以及候选资源文件的候选本地地址。S328, determining the basic local address of the basic resource file and the candidate local addresses of the candidate resource files.
S330,对包含在线地址、基础本地地址、候选本地地址、基础资源文件、候选资源文件的待打包文件打包处理,得到程序包。S330, packaging the files to be packaged including the online address, the basic local address, the candidate local address, the basic resource file, and the candidate resource file to obtain a program package.
其中,对待打包文件打打包处理过程还包括:对包含在线地址、基础本地地址、候选本地地址的项目代码,以及基础资源文件、候选资源文件的待打包文件打包处理,得到程序包。The packaging process of the files to be packaged also includes: packaging the project codes including the online address, the basic local address, the candidate local address, and the files to be packaged including the basic resource files and the candidate resource files to obtain a program package.
S332,对包含在线地址、基础资源文件的本地地址的项目代码,以及基础资源文件打包处理,得到程序包。S332, packaging the project code including the online address, the local address of the basic resource file, and the basic resource file to obtain a program package.
其中,以上步骤得到的程序包均可以用于微信小程序的运行,微信小程序是运行在微信app内的一种不需要下载安装即可使用的应用。Among them, the program packages obtained in the above steps can all be used to run WeChat mini-programs. WeChat mini-programs are applications that run in the WeChat app and can be used without downloading and installing.
本实施例中,获取代码打包脚本以及多个静态资源文件,代码打包脚本携带有配置文件,执行代码打包脚本,基于配置文件中的配置资源属性,分别对各静态资源文件各自的静态资源属性进行匹配,得到目标资源文件和基础资源文件,目标资源文件为匹配成功的静态资源属性对应的静态资源文件,基础资源文件为匹配失败的静态资源属性对应的静态资源文件,采用打包脚本携带的配置文件划分各静态资源文件,便于后续对于不同的静态资源文件进行不同的处理。将目标资源文件上传至服务器,得到目标资源文件在服务器的在线地址,对包含在线地址、基础资源文件、基础资源文件的本地地址的待打包文件打包处理,得到程序包,无需对目标静态资源进行打包,减小了程序包的所占空间,该方法,采用脚本划分各静态资源文件自动化方式,减少了打包消耗时长,提高了打包效率。该方法,需要人工进行的繁琐、费时费力的操作均通过webpack打包脚本自动完成,减少开发人员的工作量,降低维护成本同时也降低项目的上手、学习成本。通过编写webpack脚本,自动识别使用到的资源文件并上传至服务器并对代码中的文件路径自动替换,减少开发人员的工作量,降低维护成本同时也降低项目的上手、学习成本。In this embodiment, a code packaging script and multiple static resource files are obtained. The code packaging script carries a configuration file. The code packaging script is executed. Based on the configuration resource attributes in the configuration file, the static resource attributes of each static resource file are matched respectively to obtain a target resource file and a basic resource file. The target resource file is a static resource file corresponding to the static resource attribute that successfully matches, and the basic resource file is a static resource file corresponding to the static resource attribute that fails to match. The configuration file carried by the packaging script is used to divide each static resource file, which is convenient for subsequent different processing of different static resource files. The target resource file is uploaded to the server, and the online address of the target resource file on the server is obtained. The files to be packaged containing the online address, the basic resource file, and the local address of the basic resource file are packaged and processed to obtain a program package. There is no need to package the target static resource, which reduces the space occupied by the program package. This method uses a script to divide each static resource file into an automated manner, which reduces the packaging consumption time and improves the packaging efficiency. In this method, the cumbersome, time-consuming and labor-intensive operations that need to be performed manually are automatically completed by the webpack packaging script, which reduces the workload of developers, reduces maintenance costs, and also reduces the project's start-up and learning costs. By writing webpack scripts, the resource files used are automatically identified and uploaded to the server, and the file paths in the code are automatically replaced, which reduces the workload of developers, reduces maintenance costs, and also reduces the cost of getting started and learning the project.
应该理解的是,虽然如上所述的各实施例所涉及的流程图中的各个步骤按照箭头的指示依次显示,但是这些步骤并不是必然按照箭头指示的顺序依次执行。除非本文中有明确的说明,这些步骤的执行并没有严格的顺序限制,这些步骤可以以其它的顺序执行。而且,如上所述的各实施例所涉及的流程图中的至少一部分步骤可以包括多个步骤或者多个阶段,这些步骤或者阶段并不必然是在同一时刻执行完成,而是可以在不同的时刻执行,这些步骤或者阶段的执行顺序也不必然是依次进行,而是可以与其它步骤或者其它步骤中的步骤或者阶段的至少一部分轮流或者交替地执行。It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
基于同样的发明构思,本申请实施例还提供了一种用于实现上述所涉及的文件处理方法的文件处理装置。该装置所提供的解决问题的实现方案与上述方法中所记载的实现方案相似,故下面所提供的一个或多个文件处理装置实施例中的具体限定可以参见上文中对于文件处理方法的限定,在此不再赘述。Based on the same inventive concept, the embodiment of the present application also provides a file processing device for implementing the file processing method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more file processing device embodiments provided below can refer to the limitations on the file processing method above, and will not be repeated here.
在一个实施例中,如图4所示,提供了一种文件处理装置,包括:获取模块402、匹配模块404、上传模块406和打包模块408,其中:In one embodiment, as shown in FIG. 4 , a file processing device is provided, including: an acquisition module 402, a matching module 404, an upload module 406 and a packaging module 408, wherein:
获取模块402,用于获取代码打包脚本以及多个静态资源文件,代码打包脚本携带有配置文件;The acquisition module 402 is used to acquire a code packaging script and multiple static resource files, where the code packaging script carries a configuration file;
匹配模块404,用于执行代码打包脚本,基于配置文件中的配置资源属性,分别对各静态资源文件各自的静态资源属性进行匹配,得到目标资源文件和基础资源文件,目标资源文件为匹配成功的静态资源属性对应的静态资源文件,基础资源文件为匹配失败的静态资源属性对应的静态资源文件;The matching module 404 is used to execute the code packaging script, and match the static resource attributes of each static resource file based on the configuration resource attributes in the configuration file to obtain a target resource file and a basic resource file, wherein the target resource file is a static resource file corresponding to the static resource attribute that successfully matches, and the basic resource file is a static resource file corresponding to the static resource attribute that fails to match;
上传模块406,用于将目标资源文件上传至服务器,得到目标资源文件在服务器的在线地址;The upload module 406 is used to upload the target resource file to the server and obtain the online address of the target resource file on the server;
打包模块408,用于对包含在线地址、基础资源文件、基础资源文件的本地地址的待打包文件打包处理,得到程序包。The packaging module 408 is used to package the files to be packaged including the online address, the basic resource file, and the local address of the basic resource file to obtain a program package.
在其中一个实施例中,配置资源属性包括资源类型条件和资源大小条件;静态资源属性包括静态资源类型和静态资源大小;匹配模块404,还用于执行代码打包脚本,基于配置文件中的资源类型条件,分别对各静态资源文件各自的静态资源类型进行匹配,得到资源类型条件分别与各静态资源文件之间的类型匹配结果;基于配置文件中的资源大小条件,分别对各静态资源文件各自的静态资源大小进行匹配,得到资源大小条件分别与各静态资源文件之间的大小匹配结果;根据类型匹配结果和大小匹配结果,将各静态资源文件划分为目标资源文件和基础资源文件。In one of the embodiments, the configuration resource attributes include resource type conditions and resource size conditions; the static resource attributes include static resource types and static resource sizes; the matching module 404 is also used to execute the code packaging script, and based on the resource type conditions in the configuration file, the static resource types of each static resource file are matched respectively to obtain type matching results between the resource type conditions and each static resource file; based on the resource size conditions in the configuration file, the static resource sizes of each static resource file are matched respectively to obtain size matching results between the resource size conditions and each static resource file; according to the type matching results and the size matching results, each static resource file is divided into a target resource file and a basic resource file.
在其中一个实施例中,匹配模块404,还用于按照各类型匹配结果,筛选各静态资源文件中资源类型匹配成功的静态资源文件;按照各大小匹配结果,筛选各静态资源文件中资源大小匹配成功的静态资源文件;合并资源类型匹配成功的静态资源文件和资源大小匹配成功的静态资源文件,得到目标资源文件;并将除目标资源文件以外各静态资源文件确定为基础资源文件。In one of the embodiments, the matching module 404 is also used to filter the static resource files whose resource types are successfully matched in each static resource file according to the matching results of each type; filter the static resource files whose resource sizes are successfully matched in each static resource file according to the matching results of each size; merge the static resource files whose resource types are successfully matched and the static resource files whose resource sizes are successfully matched to obtain the target resource file; and determine each static resource file except the target resource file as the basic resource file.
在其中一个实施例中,上传模块406,还用于确定与目标资源文件的静态资源属性匹配的多个候选服务器;按照各候选服务器各自的负载特征,在各候选服务器中选取目标服务器;将目标资源文件上传至目标服务器,接收目标服务器发送的目标资源文件在目标服务器的在线地址。In one of the embodiments, the upload module 406 is also used to determine multiple candidate servers that match the static resource attributes of the target resource file; select a target server from each candidate server according to the load characteristics of each candidate server; upload the target resource file to the target server, and receive the online address of the target resource file on the target server sent by the target server.
在其中一个实施例中,打包模块408,还用于在资源文件库中提取与基础资源文件存在分辨率关联关系的候选资源文件;确定基础资源文件的基础本地地址,以及候选资源文件的候选本地地址;对包含在线地址、基础本地地址、候选本地地址、基础资源文件、候选资源文件的待打包文件打包处理,得到程序包。In one of the embodiments, the packaging module 408 is also used to extract candidate resource files that have a resolution association relationship with the basic resource files in the resource file library; determine the basic local address of the basic resource file and the candidate local address of the candidate resource file; and package the files to be packaged that include the online address, the basic local address, the candidate local address, the basic resource file, and the candidate resource file to obtain a program package.
在其中一个实施例中,获取模块402,还用于获取待打包文件中的项目代码;扫描项目代码,得到项目代码对应的多个备选资源文件;对各备选资源文件进行文件类优化处理,得到多个静态资源文件;打包模块408,还用于对包含在线地址、基础资源文件的本地地址的项目代码,以及基础资源文件打包处理,得到程序包。In one of the embodiments, the acquisition module 402 is also used to obtain the project code in the file to be packaged; scan the project code to obtain multiple alternative resource files corresponding to the project code; perform file class optimization processing on each alternative resource file to obtain multiple static resource files; the packaging module 408 is also used to package the project code containing the online address, the local address of the basic resource file, and the basic resource file to obtain a program package.
上述文件处理装置中的各个模块可全部或部分通过软件、硬件及其组合来实现。上述各模块可以硬件形式内嵌于或独立于计算机设备中的处理器中,也可以以软件形式存储于计算机设备中的存储器中,以便于处理器调用执行以上各个模块对应的操作。Each module in the above-mentioned file processing device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module above.
在一个实施例中,提供了一种计算机设备,该计算机设备可以是服务器,其内部结构图可以如图5所示。该计算机设备包括处理器、存储器、输入/输出接口(Input/Output,简称I/O)和通信接口。其中,处理器、存储器和输入/输出接口通过系统总线连接,通信接口通过输入/输出接口连接到系统总线。其中,该计算机设备的处理器用于提供计算和控制能力。该计算机设备的存储器包括非易失性存储介质和内存储器。该非易失性存储介质存储有操作系统、计算机程序和数据库。该内存储器为非易失性存储介质中的操作系统和计算机程序的运行提供环境。该计算机设备的数据库用于存储静态资源文件数据。该计算机设备的输入/输出接口用于处理器与外部设备之间交换信息。该计算机设备的通信接口用于与外部的终端通过网络连接通信。该计算机程序被处理器执行时以实现一种文件处理方法。In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be shown in FIG5. The computer device includes a processor, a memory, an input/output interface (Input/Output, referred to as I/O) and a communication interface. The processor, the memory and the input/output interface are connected via a system bus, and the communication interface is connected to the system bus via the input/output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store static resource file data. The input/output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a file processing method is implemented.
本领域技术人员可以理解,图5中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备的限定,具体的计算机设备可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。Those skilled in the art will understand that the structure shown in FIG. 5 is merely a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
在一个实施例中,提供了一种计算机设备,包括存储器和处理器,存储器中存储有计算机程序,该处理器执行计算机程序时实现以上方法步骤。In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the above method steps are implemented when the processor executes the computer program.
在一个实施例中,提供了一种计算机可读存储介质,其上存储有计算机程序,计算机程序被处理器执行时以上方法步骤。In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the above method steps are performed.
在一个实施例中,提供了一种计算机程序产品,包括计算机程序,该计算机程序被处理器执行时以上方法步骤。In one embodiment, a computer program product is provided, comprising a computer program, wherein the computer program performs the above method steps when executed by a processor.
需要说明的是,本申请所涉及的用户信息(包括但不限于用户设备信息、用户个人信息等)和数据(包括但不限于用于分析的数据、存储的数据、展示的数据等),均为经用户授权或者经过各方充分授权的信息和数据。并且,对数据的获取、存储、处理、传输等均符合法律法规的相关规定。It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. In addition, the acquisition, storage, processing, and transmission of data are in compliance with relevant laws and regulations.
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一非易失性计算机可读取存储介质中,该计算机程序在执行时,可包括如上述各方法的实施例的流程。其中,本申请所提供的各实施例中所使用的对存储器、数据库或其它介质的任何引用,均可包括非易失性和易失性存储器中的至少一种。非易失性存储器可包括只读存储器(Read-OnlyMemory,ROM)、磁带、软盘、闪存、光存储器、高密度嵌入式非易失性存储器、阻变存储器(ReRAM)、磁变存储器(Magnetoresistive Random Access Memory,MRAM)、铁电存储器(Ferroelectric Random Access Memory,FRAM)、相变存储器(Phase Change Memory,PCM)、石墨烯存储器等。易失性存储器可包括随机存取存储器(Random Access Memory,RAM)或外部高速缓冲存储器等。作为说明而非局限,RAM可以是多种形式,比如静态随机存取存储器(Static Random Access Memory,SRAM)或动态随机存取存储器(Dynamic RandomAccess Memory,DRAM)等。本申请所提供的各实施例中所涉及的数据库可包括关系型数据库和非关系型数据库中至少一种。非关系型数据库可包括基于区块链的分布式数据库等,不限于此。本申请所提供的各实施例中所涉及的处理器可为通用处理器、中央处理器、图形处理器、数字信号处理器、可编程逻辑器、基于量子计算的数据处理逻辑器等,不限于此。Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
以上实施例的各技术特征可以进行任意的组合,为使描述简洁,未对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
以上所述实施例仅表达了本申请的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对本申请专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本申请构思的前提下,还可以做出若干变形和改进,这些都属于本申请的保护范围。因此,本申请的保护范围应以所附权利要求为准。The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410718867.4A CN118626135A (en) | 2024-06-05 | 2024-06-05 | File processing method, device, computer equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410718867.4A CN118626135A (en) | 2024-06-05 | 2024-06-05 | File processing method, device, computer equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN118626135A true CN118626135A (en) | 2024-09-10 |
Family
ID=92602515
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202410718867.4A Pending CN118626135A (en) | 2024-06-05 | 2024-06-05 | File processing method, device, computer equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN118626135A (en) |
-
2024
- 2024-06-05 CN CN202410718867.4A patent/CN118626135A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US20220253588A1 (en) | Page processing method and related apparatus | |
CN108536745B (en) | Shell-based data table extraction method, terminal, equipment and storage medium | |
CN110457260A (en) | File processing method, device, device, and computer-readable storage medium | |
CN111444158B (en) | Long-term and short-term user portrait generation method, device, equipment and readable storage medium | |
CN111400246B (en) | Asynchronous file import method, device, computer equipment and storage medium | |
CN110018845B (en) | Metadata version comparison method and device | |
CN110059278A (en) | Web page configuration method, server and computer readable storage medium | |
CN110888972A (en) | Sensitive content identification method and device based on Spark Streaming | |
CN118245699A (en) | Page acquisition method, device, equipment, storage medium and computer program product | |
CN111158733A (en) | A kind of BMC upgrade method, apparatus, equipment and computer readable storage medium | |
CN117435651A (en) | Test data processing method, device, computer equipment and storage medium | |
CN118626135A (en) | File processing method, device, computer equipment and storage medium | |
CN114647411B (en) | Programming interface loading method, device, electronic device and storage medium | |
CN116860576A (en) | Method, device, computer equipment and storage medium for recording operation log | |
CN116821533A (en) | Page rendering method, computer device and computer-readable storage medium | |
CN116861120A (en) | Webpage resource loading method and device, computer equipment and storage medium | |
CN114968725A (en) | Task dependency relationship correction method and device, computer equipment and storage medium | |
CN113805854A (en) | Method, system and device for realizing Hook of application layer based on Linux system and storage medium | |
CN117493113B (en) | Data reporting method, device, computer equipment and storage medium | |
CN119105750A (en) | Web page development tool parameter setting method and web page development tool parameter application method | |
JP7180681B2 (en) | Information processing device, control method, and program | |
CN118606578A (en) | Web page conversion method, device, computer equipment, readable storage medium and program product | |
CN117056228A (en) | Page loading test method and device, computer equipment and storage medium | |
CN118606273A (en) | Polyhedral mesh-based file conversion method and terminal device | |
CN118606302A (en) | A configuration method, device, equipment and storage medium for management function template |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |