Skip to content

Commit

Permalink
上传文件增加存储 url 字段,方便业务端下载
Browse files Browse the repository at this point in the history
  • Loading branch information
mcxinyu committed Mar 7, 2023
1 parent 39b463a commit d97c49c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 25 deletions.
28 changes: 10 additions & 18 deletions file-plugin/src/main/kotlin/com/imf/plugin/so/HandleSoFileInfo.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
package com.imf.plugin.so

class HandleSoFileInfo(val saveCompressToAssets: Boolean, val md5: String?, val dependencies: List<String>?, val compressName: String?) {
import com.google.gson.Gson

data class HandleSoFileInfo(
var saveCompressToAssets: Boolean,
var md5: String?,
var dependencies: List<String>? = null,
var compressName: String? = null,
var url: String? = null
) {
//用于生成json
override fun toString(): String {
val s = StringBuilder("{\"saveCompressToAssets\":${saveCompressToAssets}")
if (!dependencies.isNullOrEmpty()) {
s.append(",\"dependencies\":[\"${dependencies[0]}\"")
for (index in 1 until dependencies.size) {
s.append(",\"${dependencies[index]}\"")
}
s.append(']')
}
md5?.let {
s.append(",\"md5\":\"${md5}\"")
}
compressName?.let {
s.append(",\"compressName\":\"${compressName}\"")
}
return s.append('}').toString()
}
override fun toString(): String = Gson().toJson(this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ open class SoFileExtensions {
*/
var backupDeleteSo: Boolean = true

var onDeleteSo: ((File, String) -> Unit)? = null
var onDeleteSo: ((File, String) -> String)? = null

/**
* 压缩放在 assets 下的 so 库
Expand Down
4 changes: 3 additions & 1 deletion file-plugin/src/main/kotlin/com/imf/plugin/so/SoHandle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ class SoHandle(
FileUtils.copyFile(it, this)
}
} else it
extension.onDeleteSo?.invoke(soFile, md5)
extension.onDeleteSo?.invoke(soFile, md5)?.let { url ->
recordMap[unmapLibraryName(name)]?.url = url
}
it.delete()
}
}
Expand Down
2 changes: 1 addition & 1 deletion load-assets-7z/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
dependencies {
implementation project(":load-hook")
implementation project(":android-un7z")
implementation("androidx.annotation:annotation:1.6.0")
implementation("com.android.tools:annotations:30.4.2")
}

task sourcesJar(type: Jar) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.imf.so.assets.load;

import androidx.annotation.Nullable;

import com.android.annotations.Nullable;
import com.imf.so.assets.load.bean.SoFileInfo;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ public class SoFileInfo {
public String md5;
public String compressName;
public List<String> dependencies;
public String url;

private SoFileInfo(String libName, String abi, boolean saveCompressToAssets, String md5, String compressName, List<String> dependencies) {
private SoFileInfo(String libName, String abi, boolean saveCompressToAssets, String md5, String compressName, List<String> dependencies, String url) {
this.libName = libName;
this.abi = abi;
this.saveCompressToAssets = saveCompressToAssets;
this.md5 = md5;
this.compressName = compressName;
this.dependencies = dependencies;
this.url = url;
}


Expand Down Expand Up @@ -69,7 +71,8 @@ public static SoFileInfo fromJson(JSONObject json, String abi, String libName) {
}
}
}
return new SoFileInfo(libName, abi, saveCompressToAssets, md5, compressName, dependencies);
String aUrl = targetSoInfo.optString("url");
return new SoFileInfo(libName, abi, saveCompressToAssets, md5, compressName, dependencies, aUrl);
}
return null;
}
Expand Down
6 changes: 6 additions & 0 deletions so-file-config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ SoFileConfig {
'libsource.so',
'libblur-lib.so',
]
/**
* 移除 so 时回调,这里可以做上传云端的逻辑
*/
onDeleteSo = { File file, String md5 ->
return file.absolutePath.replace(".so", "_${md5}.so")
}
// 设置要压缩的库 注意 libun7zip.so 为 7z 解压库不可压缩
compressSo2AssetsLibs = [

Expand Down

0 comments on commit d97c49c

Please sign in to comment.