expo-asset 9.0.2 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -1
- package/android/build.gradle +19 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/expo/modules/asset/AssetModule.kt +89 -0
- package/app.plugin.js +1 -0
- package/build/Asset.d.ts +10 -20
- package/build/Asset.d.ts.map +1 -1
- package/build/Asset.fx.js +2 -2
- package/build/Asset.fx.js.map +1 -1
- package/build/Asset.js +7 -15
- package/build/Asset.js.map +1 -1
- package/build/AssetSourceResolver.d.ts +3 -3
- package/build/AssetSourceResolver.d.ts.map +1 -1
- package/build/AssetSourceResolver.js.map +1 -1
- package/build/AssetSources.d.ts.map +1 -1
- package/build/AssetSources.js +2 -18
- package/build/AssetSources.js.map +1 -1
- package/build/AssetUris.js.map +1 -1
- package/build/ExpoAsset.d.ts +11 -0
- package/build/ExpoAsset.d.ts.map +1 -0
- package/build/ExpoAsset.js +15 -0
- package/build/ExpoAsset.js.map +1 -0
- package/build/ExpoAsset.web.d.ts +5 -0
- package/build/ExpoAsset.web.d.ts.map +1 -0
- package/build/ExpoAsset.web.js +6 -0
- package/build/ExpoAsset.web.js.map +1 -0
- package/build/ImageAssets.js.map +1 -1
- package/build/LocalAssets.js.map +1 -1
- package/build/PlatformUtils.d.ts +4 -11
- package/build/PlatformUtils.d.ts.map +1 -1
- package/build/PlatformUtils.js +15 -68
- package/build/PlatformUtils.js.map +1 -1
- package/build/PlatformUtils.web.d.ts +0 -3
- package/build/PlatformUtils.web.d.ts.map +1 -1
- package/build/PlatformUtils.web.js +0 -5
- package/build/PlatformUtils.web.js.map +1 -1
- package/build/resolveAssetSource.js.map +1 -1
- package/expo-module.config.json +7 -1
- package/ios/AssetModule.swift +92 -0
- package/ios/ExpoAsset.podspec +27 -0
- package/mocks/ExpoAsset.ts +12 -0
- package/package.json +8 -7
- package/plugin/build/utils.d.ts +6 -0
- package/plugin/build/utils.js +42 -0
- package/plugin/build/withAssets.d.ts +6 -0
- package/plugin/build/withAssets.js +18 -0
- package/plugin/build/withAssetsAndroid.d.ts +2 -0
- package/plugin/build/withAssetsAndroid.js +48 -0
- package/plugin/build/withAssetsIos.d.ts +2 -0
- package/plugin/build/withAssetsIos.js +82 -0
- package/plugin/src/utils.ts +41 -0
- package/plugin/src/withAssets.ts +27 -0
- package/plugin/src/withAssetsAndroid.ts +46 -0
- package/plugin/src/withAssetsIos.ts +102 -0
- package/plugin/tsconfig.json +9 -0
- package/src/Asset.fx.ts +2 -2
- package/src/Asset.ts +20 -26
- package/src/AssetSourceResolver.ts +3 -3
- package/src/AssetSources.ts +1 -20
- package/src/ExpoAsset.ts +20 -0
- package/src/ExpoAsset.web.ts +5 -0
- package/src/PlatformUtils.ts +21 -81
- package/src/PlatformUtils.web.ts +0 -6
- package/src/resolveAssetSource.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,7 +10,29 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## 10.0.0 — 2024-04-18
|
|
14
|
+
|
|
15
|
+
### 🎉 New features
|
|
16
|
+
|
|
17
|
+
- Added config plugin to allow assets to be linked at build time. ([#27052](https://github.com/expo/expo/pull/27052) by [@alanjhughes](https://github.com/alanjhughes))
|
|
18
|
+
- Add Apple TV support to the new iOS native module. ([#27823](https://github.com/expo/expo/pull/27823) by [@douglowder](https://github.com/douglowder))
|
|
19
|
+
|
|
20
|
+
### 🐛 Bug fixes
|
|
21
|
+
|
|
22
|
+
- Fixed "Tried to resolve a promise more than once" crash on iOS. ([#27672](https://github.com/expo/expo/pull/27672) by [@kudo](https://github.com/kudo))
|
|
23
|
+
|
|
24
|
+
### 💡 Others
|
|
25
|
+
|
|
26
|
+
- Create native module for iOS and Android. Migrate `downloadAsync` to a native implementation. ([#27369](https://github.com/expo/expo/pull/27369) by [@aleqsio](https://github.com/aleqsio))
|
|
27
|
+
- Remove MD5 checksum verification for remote assets. This does not change method signatures nor require changes to your application code, and should not affect any apps in practice since this behavior was used only for apps that used Classic Updates, support for which ended with SDK 50. ([#25614](https://github.com/expo/expo/pull/25614) by [@ide](https://github.com/ide))
|
|
28
|
+
- [expo-updates] Migrate to requireNativeModule/requireOptionalNativeModule. ([#25648](https://github.com/expo/expo/pull/25648) by [@wschurman](https://github.com/wschurman))
|
|
29
|
+
- Clean up some asset stuff. ([#26310](https://github.com/expo/expo/pull/26310) by [@wschurman](https://github.com/wschurman))
|
|
30
|
+
- Remove most of Constants.appOwnership. ([#26313](https://github.com/expo/expo/pull/26313) by [@wschurman](https://github.com/wschurman))
|
|
31
|
+
- Remove assetUrlOverride and assetMapOverride. ([#26314](https://github.com/expo/expo/pull/26314) by [@wschurman](https://github.com/wschurman))
|
|
32
|
+
- Improve updates types and clarity in expo-asset. ([#26337](https://github.com/expo/expo/pull/26337) by [@wschurman](https://github.com/wschurman))
|
|
33
|
+
- Removed deprecated backward compatible Gradle settings. ([#28083](https://github.com/expo/expo/pull/28083) by [@kudo](https://github.com/kudo))
|
|
34
|
+
|
|
35
|
+
## 9.0.2 - 2024-01-05
|
|
14
36
|
|
|
15
37
|
### 🐛 Bug fixes
|
|
16
38
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
|
|
3
|
+
group = 'expo.modules.asset'
|
|
4
|
+
version = '10.0.0'
|
|
5
|
+
|
|
6
|
+
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
7
|
+
apply from: expoModulesCorePlugin
|
|
8
|
+
applyKotlinExpoModulesCorePlugin()
|
|
9
|
+
useCoreDependencies()
|
|
10
|
+
useDefaultAndroidSdkVersions()
|
|
11
|
+
useExpoPublishing()
|
|
12
|
+
|
|
13
|
+
android {
|
|
14
|
+
namespace "expo.modules.asset"
|
|
15
|
+
defaultConfig {
|
|
16
|
+
versionCode 1
|
|
17
|
+
versionName "10.0.0"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
package expo.modules.asset
|
|
2
|
+
|
|
3
|
+
import android.net.Uri
|
|
4
|
+
import expo.modules.interfaces.filesystem.Permission
|
|
5
|
+
import expo.modules.kotlin.AppContext
|
|
6
|
+
import expo.modules.kotlin.exception.CodedException
|
|
7
|
+
import expo.modules.kotlin.functions.Coroutine
|
|
8
|
+
import expo.modules.kotlin.modules.Module
|
|
9
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
10
|
+
import kotlinx.coroutines.withContext
|
|
11
|
+
import java.io.File
|
|
12
|
+
import java.io.FileInputStream
|
|
13
|
+
import java.net.URI
|
|
14
|
+
import java.security.DigestInputStream
|
|
15
|
+
import java.security.MessageDigest
|
|
16
|
+
|
|
17
|
+
internal class UnableToDownloadAssetException(url: String) :
|
|
18
|
+
CodedException("Unable to download asset from url: $url")
|
|
19
|
+
|
|
20
|
+
class AssetModule : Module() {
|
|
21
|
+
private fun getMD5HashOfFilePath(uri: URI): String {
|
|
22
|
+
val md = MessageDigest.getInstance("MD5")
|
|
23
|
+
return md.digest(uri.toString().toByteArray()).joinToString("") { "%02x".format(it) }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private fun getMD5HashOfFileContent(file: File): String? {
|
|
27
|
+
return try {
|
|
28
|
+
FileInputStream(file).use { inputStream ->
|
|
29
|
+
DigestInputStream(
|
|
30
|
+
inputStream,
|
|
31
|
+
MessageDigest.getInstance("MD5")
|
|
32
|
+
).use { digestInputStream ->
|
|
33
|
+
digestInputStream.messageDigest.digest().joinToString(separator = "") { "%02x".format(it) }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} catch (e: Exception) {
|
|
37
|
+
e.printStackTrace()
|
|
38
|
+
null
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private suspend fun downloadAsset(appContext: AppContext, uri: URI, localUrl: File): Uri {
|
|
43
|
+
if (localUrl.parentFile?.exists() != true) {
|
|
44
|
+
localUrl.mkdirs()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (appContext.filePermission?.getPathPermissions(appContext.reactContext, localUrl.parent)?.contains(Permission.WRITE) != true) {
|
|
48
|
+
throw UnableToDownloadAssetException(uri.toString())
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return withContext(appContext.backgroundCoroutineScope.coroutineContext) {
|
|
52
|
+
try {
|
|
53
|
+
uri.toURL().openStream().use { input ->
|
|
54
|
+
localUrl.outputStream().use { output ->
|
|
55
|
+
input.copyTo(output)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
Uri.fromFile(localUrl)
|
|
59
|
+
} catch (e: Exception) {
|
|
60
|
+
throw UnableToDownloadAssetException(uri.toString())
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
override fun definition() = ModuleDefinition {
|
|
66
|
+
Name("ExpoAsset")
|
|
67
|
+
|
|
68
|
+
AsyncFunction("downloadAsync") Coroutine { uri: URI, md5Hash: String?, type: String ->
|
|
69
|
+
if (uri.scheme === "file") {
|
|
70
|
+
return@Coroutine uri
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
val cacheFileId = md5Hash ?: getMD5HashOfFilePath(uri)
|
|
74
|
+
val cacheDirectory = appContext.cacheDirectory
|
|
75
|
+
|
|
76
|
+
val localUrl = File("$cacheDirectory/ExponentAsset-$cacheFileId.$type")
|
|
77
|
+
|
|
78
|
+
if (!localUrl.exists()) {
|
|
79
|
+
return@Coroutine downloadAsset(appContext, uri, localUrl)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (md5Hash == null || md5Hash == getMD5HashOfFileContent(localUrl)) {
|
|
83
|
+
return@Coroutine Uri.fromFile(localUrl)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return@Coroutine downloadAsset(appContext, uri, localUrl)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
package/app.plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./plugin/build/withAssets');
|
package/build/Asset.d.ts
CHANGED
|
@@ -7,24 +7,14 @@ export type AssetDescriptor = {
|
|
|
7
7
|
width?: number | null;
|
|
8
8
|
height?: number | null;
|
|
9
9
|
};
|
|
10
|
-
type DownloadPromiseCallbacks = {
|
|
11
|
-
resolve: () => void;
|
|
12
|
-
reject: (error: Error) => void;
|
|
13
|
-
};
|
|
14
10
|
export { AssetMetadata };
|
|
15
11
|
/**
|
|
16
12
|
* The `Asset` class represents an asset in your app. It gives metadata about the asset (such as its
|
|
17
13
|
* name and type) and provides facilities to load the asset data.
|
|
18
14
|
*/
|
|
19
15
|
export declare class Asset {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*/
|
|
23
|
-
static byHash: {};
|
|
24
|
-
/**
|
|
25
|
-
* @private
|
|
26
|
-
*/
|
|
27
|
-
static byUri: {};
|
|
16
|
+
private static byHash;
|
|
17
|
+
private static byUri;
|
|
28
18
|
/**
|
|
29
19
|
* The name of the asset file without the extension. Also without the part from `@` onward in the
|
|
30
20
|
* filename (used to specify scale factor for images).
|
|
@@ -33,11 +23,11 @@ export declare class Asset {
|
|
|
33
23
|
/**
|
|
34
24
|
* The extension of the asset filename.
|
|
35
25
|
*/
|
|
36
|
-
type: string;
|
|
26
|
+
readonly type: string;
|
|
37
27
|
/**
|
|
38
28
|
* The MD5 hash of the asset's data.
|
|
39
29
|
*/
|
|
40
|
-
hash: string | null;
|
|
30
|
+
readonly hash: string | null;
|
|
41
31
|
/**
|
|
42
32
|
* A URI that points to the asset's data on the remote server. When running the published version
|
|
43
33
|
* of your app, this refers to the location on Expo's asset server where Expo has stored your
|
|
@@ -46,7 +36,7 @@ export declare class Asset {
|
|
|
46
36
|
* are not using Classic Updates (legacy), this field should be ignored as we ensure your assets
|
|
47
37
|
* are on device before before running your application logic.
|
|
48
38
|
*/
|
|
49
|
-
uri: string;
|
|
39
|
+
readonly uri: string;
|
|
50
40
|
/**
|
|
51
41
|
* If the asset has been downloaded (by calling [`downloadAsync()`](#downloadasync)), the
|
|
52
42
|
* `file://` URI pointing to the local file on the device that contains the asset data.
|
|
@@ -61,12 +51,12 @@ export declare class Asset {
|
|
|
61
51
|
* If the asset is an image, the height of the image data divided by the scale factor. The scale factor is the number after `@` in the filename, or `1` if not present.
|
|
62
52
|
*/
|
|
63
53
|
height: number | null;
|
|
64
|
-
downloading
|
|
65
|
-
downloaded: boolean;
|
|
54
|
+
private downloading;
|
|
66
55
|
/**
|
|
67
|
-
*
|
|
56
|
+
* Whether the asset has finished downloading from a call to [`downloadAsync()`](#downloadasync).
|
|
68
57
|
*/
|
|
69
|
-
|
|
58
|
+
downloaded: boolean;
|
|
59
|
+
private _downloadCallbacks;
|
|
70
60
|
constructor({ name, type, hash, uri, width, height }: AssetDescriptor);
|
|
71
61
|
/**
|
|
72
62
|
* A helper that wraps `Asset.fromModule(module).downloadAsync` for convenience.
|
|
@@ -91,7 +81,7 @@ export declare class Asset {
|
|
|
91
81
|
static fromURI(uri: string): Asset;
|
|
92
82
|
/**
|
|
93
83
|
* Downloads the asset data to a local file in the device's cache directory. Once the returned
|
|
94
|
-
* promise is fulfilled without error, the [`localUri`](#
|
|
84
|
+
* promise is fulfilled without error, the [`localUri`](#localuri) field of this asset points
|
|
95
85
|
* to a local file containing the asset data. The asset is only downloaded if an up-to-date local
|
|
96
86
|
* file for the asset isn't already present due to an earlier download. The downloaded `Asset`
|
|
97
87
|
* will be returned when the promise is resolved.
|
package/build/Asset.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Asset.d.ts","sourceRoot":"","sources":["../src/Asset.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAqB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Asset.d.ts","sourceRoot":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AAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAMnF;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,kBAAkB,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK;IA0C7D,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,KAAK;IAsB/C,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IA2BlC;;;;;;;OAOG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;CAoCrC"}
|
package/build/Asset.fx.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Asset } from './Asset';
|
|
2
|
-
import {
|
|
2
|
+
import { IS_ENV_WITH_LOCAL_ASSETS } from './PlatformUtils';
|
|
3
3
|
import { setCustomSourceTransformer } from './resolveAssetSource';
|
|
4
4
|
// Override React Native's asset resolution for `Image` components in contexts where it matters
|
|
5
|
-
if (
|
|
5
|
+
if (IS_ENV_WITH_LOCAL_ASSETS) {
|
|
6
6
|
setCustomSourceTransformer((resolver) => {
|
|
7
7
|
try {
|
|
8
8
|
// Bundler is using the hashAssetFiles plugin if and only if the fileHashes property exists
|
package/build/Asset.fx.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Asset.fx.js","sourceRoot":"","sources":["../src/Asset.fx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Asset.fx.js","sourceRoot":"","sources":["../src/Asset.fx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAElE,+FAA+F;AAC/F,IAAI,wBAAwB,EAAE,CAAC;IAC7B,0BAA0B,CAAC,CAAC,QAAQ,EAAE,EAAE;QACtC,IAAI,CAAC;YACH,2FAA2F;YAC3F,IAAI,QAAQ,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;gBAC9B,MAAM,KAAK,GAAG,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACjD,OAAO,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,QAAS,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC7E,CAAC;iBAAM,CAAC;gBACN,OAAO,QAAQ,CAAC,YAAY,EAAE,CAAC;YACjC,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,QAAQ,CAAC,YAAY,EAAE,CAAC;QACjC,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Asset } from './Asset';\nimport { IS_ENV_WITH_LOCAL_ASSETS } from './PlatformUtils';\nimport { setCustomSourceTransformer } from './resolveAssetSource';\n\n// Override React Native's asset resolution for `Image` components in contexts where it matters\nif (IS_ENV_WITH_LOCAL_ASSETS) {\n setCustomSourceTransformer((resolver) => {\n try {\n // Bundler is using the hashAssetFiles plugin if and only if the fileHashes property exists\n if (resolver.asset.fileHashes) {\n const asset = Asset.fromMetadata(resolver.asset);\n return resolver.fromSource(asset.downloaded ? asset.localUri! : asset.uri);\n } else {\n return resolver.defaultAsset();\n }\n } catch {\n return resolver.defaultAsset();\n }\n });\n}\n"]}
|
package/build/Asset.js
CHANGED
|
@@ -2,23 +2,17 @@ import { getAssetByID } from '@react-native/assets-registry/registry';
|
|
|
2
2
|
import { Platform } from 'expo-modules-core';
|
|
3
3
|
import { selectAssetSource } from './AssetSources';
|
|
4
4
|
import * as AssetUris from './AssetUris';
|
|
5
|
+
import { downloadAsync } from './ExpoAsset';
|
|
5
6
|
import * as ImageAssets from './ImageAssets';
|
|
6
7
|
import { getLocalAssetUri } from './LocalAssets';
|
|
7
|
-
import {
|
|
8
|
+
import { IS_ENV_WITH_LOCAL_ASSETS } from './PlatformUtils';
|
|
8
9
|
import resolveAssetSource from './resolveAssetSource';
|
|
9
|
-
// @needsAudit
|
|
10
10
|
/**
|
|
11
11
|
* The `Asset` class represents an asset in your app. It gives metadata about the asset (such as its
|
|
12
12
|
* name and type) and provides facilities to load the asset data.
|
|
13
13
|
*/
|
|
14
14
|
export class Asset {
|
|
15
|
-
/**
|
|
16
|
-
* @private
|
|
17
|
-
*/
|
|
18
15
|
static byHash = {};
|
|
19
|
-
/**
|
|
20
|
-
* @private
|
|
21
|
-
*/
|
|
22
16
|
static byUri = {};
|
|
23
17
|
/**
|
|
24
18
|
* The name of the asset file without the extension. Also without the part from `@` onward in the
|
|
@@ -56,13 +50,11 @@ export class Asset {
|
|
|
56
50
|
* If the asset is an image, the height of the image data divided by the scale factor. The scale factor is the number after `@` in the filename, or `1` if not present.
|
|
57
51
|
*/
|
|
58
52
|
height = null;
|
|
59
|
-
// @docsMissing
|
|
60
53
|
downloading = false;
|
|
61
|
-
// @docsMissing
|
|
62
|
-
downloaded = false;
|
|
63
54
|
/**
|
|
64
|
-
*
|
|
55
|
+
* Whether the asset has finished downloading from a call to [`downloadAsync()`](#downloadasync).
|
|
65
56
|
*/
|
|
57
|
+
downloaded = false;
|
|
66
58
|
_downloadCallbacks = [];
|
|
67
59
|
constructor({ name, type, hash = null, uri, width, height }) {
|
|
68
60
|
this.name = name;
|
|
@@ -123,7 +115,7 @@ export class Asset {
|
|
|
123
115
|
}
|
|
124
116
|
// Outside of the managed env we need the moduleId to initialize the asset
|
|
125
117
|
// because resolveAssetSource depends on it
|
|
126
|
-
if (!
|
|
118
|
+
if (!IS_ENV_WITH_LOCAL_ASSETS) {
|
|
127
119
|
// null-check is performed above with `getAssetByID`.
|
|
128
120
|
const { uri } = resolveAssetSource(virtualAssetModule);
|
|
129
121
|
const asset = new Asset({
|
|
@@ -193,7 +185,7 @@ export class Asset {
|
|
|
193
185
|
// @needsAudit
|
|
194
186
|
/**
|
|
195
187
|
* Downloads the asset data to a local file in the device's cache directory. Once the returned
|
|
196
|
-
* promise is fulfilled without error, the [`localUri`](#
|
|
188
|
+
* promise is fulfilled without error, the [`localUri`](#localuri) field of this asset points
|
|
197
189
|
* to a local file containing the asset data. The asset is only downloaded if an up-to-date local
|
|
198
190
|
* file for the asset isn't already present due to an earlier download. The downloaded `Asset`
|
|
199
191
|
* will be returned when the promise is resolved.
|
|
@@ -222,7 +214,7 @@ export class Asset {
|
|
|
222
214
|
this.name = AssetUris.getFilename(this.uri);
|
|
223
215
|
}
|
|
224
216
|
}
|
|
225
|
-
this.localUri = await downloadAsync(this.uri, this.hash, this.type
|
|
217
|
+
this.localUri = await downloadAsync(this.uri, this.hash, this.type);
|
|
226
218
|
this.downloaded = true;
|
|
227
219
|
this._downloadCallbacks.forEach(({ resolve }) => resolve());
|
|
228
220
|
}
|
package/build/Asset.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Asset.js","sourceRoot":"","sources":["../src/Asset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAiB,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAmBtD,cAAc;AACd;;;GAGG;AACH,MAAM,OAAO,KAAK;IAChB;;OAEG;IACH,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB;;OAEG;IACH,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC;IA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,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;oBACtC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,WAAW,CAAC,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBAC9E,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;oBACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;oBACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;iBAClB;qBAAM;oBACL,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;iBAC7C;aACF;YACD,IAAI,CAAC,QAAQ,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAE/E,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;SAC7D;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3D,MAAM,CAAC,CAAC;SACT;gBAAS;YACR,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;YACzB,IAAI,CAAC,kBAAkB,GAAG,EAAE,CAAC;SAC9B;QACD,OAAO,IAAI,CAAC;IACd,CAAC","sourcesContent":["import { getAssetByID } from '@react-native/assets-registry/registry';\nimport { Platform } from 'expo-modules-core';\n\nimport { AssetMetadata, selectAssetSource } from './AssetSources';\nimport * as AssetUris from './AssetUris';\nimport * as ImageAssets from './ImageAssets';\nimport { getLocalAssetUri } from './LocalAssets';\nimport { downloadAsync, IS_ENV_WITH_UPDATES_ENABLED } from './PlatformUtils';\nimport resolveAssetSource from './resolveAssetSource';\n\n// @docsMissing\nexport type AssetDescriptor = {\n name: string;\n type: string;\n hash?: string | null;\n uri: string;\n width?: number | null;\n height?: number | null;\n};\n\ntype DownloadPromiseCallbacks = {\n resolve: () => void;\n reject: (error: Error) => void;\n};\n\nexport { AssetMetadata };\n\n// @needsAudit\n/**\n * The `Asset` class represents an asset in your app. It gives metadata about the asset (such as its\n * name and type) and provides facilities to load the asset data.\n */\nexport class Asset {\n /**\n * @private\n */\n static byHash = {};\n /**\n * @private\n */\n static byUri = {};\n\n /**\n * The name of the asset file without the extension. Also without the part from `@` onward in the\n * filename (used to specify scale factor for images).\n */\n name: string;\n /**\n * The extension of the asset filename.\n */\n type: string;\n /**\n * The MD5 hash of the asset's data.\n */\n hash: string | null = null;\n /**\n * A URI that points to the asset's data on the remote server. When running the published version\n * of your app, this refers to the location on Expo's asset server where Expo has stored your\n * asset. When running the app from Expo CLI during development, this URI points to Expo CLI's\n * server running on your computer and the asset is served directly from your computer. If you\n * are not using Classic Updates (legacy), this field should be ignored as we ensure your assets\n * are on device before before running your application logic.\n */\n uri: string;\n /**\n * If the asset has been downloaded (by calling [`downloadAsync()`](#downloadasync)), the\n * `file://` URI pointing to the local file on the device that contains the asset data.\n */\n localUri: string | null = null;\n /**\n * If the asset is an image, the width of the image data divided by the scale factor. The scale\n * factor is the number after `@` in the filename, or `1` if not present.\n */\n width: number | null = null;\n /**\n * If the asset is an image, the height of the image data divided by the scale factor. The scale factor is the number after `@` in the filename, or `1` if not present.\n */\n height: number | null = null;\n // @docsMissing\n downloading: boolean = false;\n // @docsMissing\n downloaded: boolean = false;\n\n /**\n * @private\n */\n _downloadCallbacks: DownloadPromiseCallbacks[] = [];\n\n constructor({ name, type, hash = null, uri, width, height }: AssetDescriptor) {\n this.name = name;\n this.type = type;\n this.hash = hash;\n this.uri = uri;\n\n if (typeof width === 'number') {\n this.width = width;\n }\n if (typeof height === 'number') {\n this.height = height;\n }\n\n if (hash) {\n this.localUri = getLocalAssetUri(hash, type);\n if (this.localUri) {\n this.downloaded = true;\n }\n }\n\n if (Platform.OS === 'web') {\n if (!name) {\n this.name = AssetUris.getFilename(uri);\n }\n if (!type) {\n this.type = AssetUris.getFileExtension(uri);\n }\n }\n }\n\n // @needsAudit\n /**\n * A helper that wraps `Asset.fromModule(module).downloadAsync` for convenience.\n * @param moduleId An array of `require('path/to/file')` or external network URLs. Can also be\n * just one module or URL without an Array.\n * @return Returns a Promise that fulfills with an array of `Asset`s when the asset(s) has been\n * saved to disk.\n * @example\n * ```ts\n * const [{ localUri }] = await Asset.loadAsync(require('./assets/snack-icon.png'));\n * ```\n */\n static loadAsync(moduleId: number | number[] | string | string[]): Promise<Asset[]> {\n const moduleIds = Array.isArray(moduleId) ? moduleId : [moduleId];\n return Promise.all(moduleIds.map((moduleId) => Asset.fromModule(moduleId).downloadAsync()));\n }\n\n // @needsAudit\n /**\n * Returns the [`Asset`](#asset) instance representing an asset given its module or URL.\n * @param virtualAssetModule The value of `require('path/to/file')` for the asset or external\n * network URL\n * @return The [`Asset`](#asset) instance for the asset.\n */\n static fromModule(virtualAssetModule: number | string): Asset {\n if (typeof virtualAssetModule === 'string') {\n return Asset.fromURI(virtualAssetModule);\n }\n\n const meta = getAssetByID(virtualAssetModule);\n if (!meta) {\n throw new Error(`Module \"${virtualAssetModule}\" is missing from the asset registry`);\n }\n\n // Outside of the managed env we need the moduleId to initialize the asset\n // because resolveAssetSource depends on it\n if (!IS_ENV_WITH_UPDATES_ENABLED) {\n // null-check is performed above with `getAssetByID`.\n const { uri } = resolveAssetSource(virtualAssetModule)!;\n\n const asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash: meta.hash,\n uri,\n width: meta.width,\n height: meta.height,\n });\n\n // TODO: FileSystem should probably support 'downloading' from drawable\n // resources But for now it doesn't (it only supports raw resources) and\n // React Native's Image works fine with drawable resource names for\n // images.\n if (Platform.OS === 'android' && !uri.includes(':') && (meta.width || meta.height)) {\n asset.localUri = asset.uri;\n asset.downloaded = true;\n }\n\n Asset.byHash[meta.hash] = asset;\n return asset;\n }\n\n return Asset.fromMetadata(meta);\n }\n\n // @docsMissing\n static fromMetadata(meta: AssetMetadata): Asset {\n // The hash of the whole asset, not to be confused with the hash of a specific file returned\n // from `selectAssetSource`\n const metaHash = meta.hash;\n if (Asset.byHash[metaHash]) {\n return Asset.byHash[metaHash];\n }\n\n const { uri, hash } = selectAssetSource(meta);\n const asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash,\n uri,\n width: meta.width,\n height: meta.height,\n });\n Asset.byHash[metaHash] = asset;\n return asset;\n }\n\n // @docsMissing\n static fromURI(uri: string): Asset {\n if (Asset.byUri[uri]) {\n return Asset.byUri[uri];\n }\n\n // Possibly a Base64-encoded URI\n let type = '';\n if (uri.indexOf(';base64') > -1) {\n type = uri.split(';')[0].split('/')[1];\n } else {\n const extension = AssetUris.getFileExtension(uri);\n type = extension.startsWith('.') ? extension.substring(1) : extension;\n }\n\n const asset = new Asset({\n name: '',\n type,\n hash: null,\n uri,\n });\n\n Asset.byUri[uri] = asset;\n\n return asset;\n }\n\n // @needsAudit\n /**\n * Downloads the asset data to a local file in the device's cache directory. Once the returned\n * promise is fulfilled without error, the [`localUri`](#assetlocaluri) field of this asset points\n * to a local file containing the asset data. The asset is only downloaded if an up-to-date local\n * file for the asset isn't already present due to an earlier download. The downloaded `Asset`\n * will be returned when the promise is resolved.\n * @return Returns a Promise which fulfills with an `Asset` instance.\n */\n async downloadAsync(): Promise<this> {\n if (this.downloaded) {\n return this;\n }\n if (this.downloading) {\n await new Promise<void>((resolve, reject) => {\n this._downloadCallbacks.push({ resolve, reject });\n });\n return this;\n }\n this.downloading = true;\n\n try {\n if (Platform.OS === 'web') {\n if (ImageAssets.isImageType(this.type)) {\n const { width, height, name } = await ImageAssets.getImageInfoAsync(this.uri);\n this.width = width;\n this.height = height;\n this.name = name;\n } else {\n this.name = AssetUris.getFilename(this.uri);\n }\n }\n this.localUri = await downloadAsync(this.uri, this.hash, this.type, this.name);\n\n this.downloaded = true;\n this._downloadCallbacks.forEach(({ resolve }) => resolve());\n } catch (e) {\n this._downloadCallbacks.forEach(({ reject }) => reject(e));\n throw e;\n } finally {\n this.downloading = false;\n this._downloadCallbacks = [];\n }\n return this;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Asset.js","sourceRoot":"","sources":["../src/Asset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAiB,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAmBtD;;;GAGG;AACH,MAAM,OAAO,KAAK;IACR,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC;IAE1B;;;OAGG;IACI,IAAI,CAAS;IACpB;;OAEG;IACa,IAAI,CAAS;IAC7B;;OAEG;IACa,IAAI,GAAkB,IAAI,CAAC;IAC3C;;;;;;;OAOG;IACa,GAAG,CAAS;IAC5B;;;OAGG;IACI,QAAQ,GAAkB,IAAI,CAAC;IACtC;;;OAGG;IACI,KAAK,GAAkB,IAAI,CAAC;IACnC;;OAEG;IACI,MAAM,GAAkB,IAAI,CAAC;IAE5B,WAAW,GAAY,KAAK,CAAC;IAErC;;OAEG;IACI,UAAU,GAAY,KAAK,CAAC;IAE3B,kBAAkB,GAA+B,EAAE,CAAC;IAE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KAAK,GAAG,KAAK,CAAC;oBACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;oBACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;gBACnB,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAC9C,CAAC;YACH,CAAC;YACD,IAAI,CAAC,QAAQ,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAEpE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9D,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3D,MAAM,CAAC,CAAC;QACV,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;YACzB,IAAI,CAAC,kBAAkB,GAAG,EAAE,CAAC;QAC/B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC","sourcesContent":["import { getAssetByID } from '@react-native/assets-registry/registry';\nimport { Platform } from 'expo-modules-core';\n\nimport { AssetMetadata, selectAssetSource } from './AssetSources';\nimport * as AssetUris from './AssetUris';\nimport { downloadAsync } from './ExpoAsset';\nimport * as ImageAssets from './ImageAssets';\nimport { getLocalAssetUri } from './LocalAssets';\nimport { IS_ENV_WITH_LOCAL_ASSETS } from './PlatformUtils';\nimport resolveAssetSource from './resolveAssetSource';\n\n// @docsMissing\nexport type AssetDescriptor = {\n name: string;\n type: string;\n hash?: string | null;\n uri: string;\n width?: number | null;\n height?: number | null;\n};\n\ntype DownloadPromiseCallbacks = {\n resolve: () => void;\n reject: (error: Error) => void;\n};\n\nexport { AssetMetadata };\n\n/**\n * The `Asset` class represents an asset in your app. It gives metadata about the asset (such as its\n * name and type) and provides facilities to load the asset data.\n */\nexport class Asset {\n private static byHash = {};\n private static byUri = {};\n\n /**\n * The name of the asset file without the extension. Also without the part from `@` onward in the\n * filename (used to specify scale factor for images).\n */\n public name: string;\n /**\n * The extension of the asset filename.\n */\n public readonly type: string;\n /**\n * The MD5 hash of the asset's data.\n */\n public readonly hash: string | null = null;\n /**\n * A URI that points to the asset's data on the remote server. When running the published version\n * of your app, this refers to the location on Expo's asset server where Expo has stored your\n * asset. When running the app from Expo CLI during development, this URI points to Expo CLI's\n * server running on your computer and the asset is served directly from your computer. If you\n * are not using Classic Updates (legacy), this field should be ignored as we ensure your assets\n * are on device before before running your application logic.\n */\n public readonly uri: string;\n /**\n * If the asset has been downloaded (by calling [`downloadAsync()`](#downloadasync)), the\n * `file://` URI pointing to the local file on the device that contains the asset data.\n */\n public localUri: string | null = null;\n /**\n * If the asset is an image, the width of the image data divided by the scale factor. The scale\n * factor is the number after `@` in the filename, or `1` if not present.\n */\n public width: number | null = null;\n /**\n * If the asset is an image, the height of the image data divided by the scale factor. The scale factor is the number after `@` in the filename, or `1` if not present.\n */\n public height: number | null = null;\n\n private downloading: boolean = false;\n\n /**\n * Whether the asset has finished downloading from a call to [`downloadAsync()`](#downloadasync).\n */\n public downloaded: boolean = false;\n\n private _downloadCallbacks: DownloadPromiseCallbacks[] = [];\n\n constructor({ name, type, hash = null, uri, width, height }: AssetDescriptor) {\n this.name = name;\n this.type = type;\n this.hash = hash;\n this.uri = uri;\n\n if (typeof width === 'number') {\n this.width = width;\n }\n if (typeof height === 'number') {\n this.height = height;\n }\n\n if (hash) {\n this.localUri = getLocalAssetUri(hash, type);\n if (this.localUri) {\n this.downloaded = true;\n }\n }\n\n if (Platform.OS === 'web') {\n if (!name) {\n this.name = AssetUris.getFilename(uri);\n }\n if (!type) {\n this.type = AssetUris.getFileExtension(uri);\n }\n }\n }\n\n // @needsAudit\n /**\n * A helper that wraps `Asset.fromModule(module).downloadAsync` for convenience.\n * @param moduleId An array of `require('path/to/file')` or external network URLs. Can also be\n * just one module or URL without an Array.\n * @return Returns a Promise that fulfills with an array of `Asset`s when the asset(s) has been\n * saved to disk.\n * @example\n * ```ts\n * const [{ localUri }] = await Asset.loadAsync(require('./assets/snack-icon.png'));\n * ```\n */\n static loadAsync(moduleId: number | number[] | string | string[]): Promise<Asset[]> {\n const moduleIds = Array.isArray(moduleId) ? moduleId : [moduleId];\n return Promise.all(moduleIds.map((moduleId) => Asset.fromModule(moduleId).downloadAsync()));\n }\n\n // @needsAudit\n /**\n * Returns the [`Asset`](#asset) instance representing an asset given its module or URL.\n * @param virtualAssetModule The value of `require('path/to/file')` for the asset or external\n * network URL\n * @return The [`Asset`](#asset) instance for the asset.\n */\n static fromModule(virtualAssetModule: number | string): Asset {\n if (typeof virtualAssetModule === 'string') {\n return Asset.fromURI(virtualAssetModule);\n }\n\n const meta = getAssetByID(virtualAssetModule);\n if (!meta) {\n throw new Error(`Module \"${virtualAssetModule}\" is missing from the asset registry`);\n }\n\n // Outside of the managed env we need the moduleId to initialize the asset\n // because resolveAssetSource depends on it\n if (!IS_ENV_WITH_LOCAL_ASSETS) {\n // null-check is performed above with `getAssetByID`.\n const { uri } = resolveAssetSource(virtualAssetModule)!;\n\n const asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash: meta.hash,\n uri,\n width: meta.width,\n height: meta.height,\n });\n\n // TODO: FileSystem should probably support 'downloading' from drawable\n // resources But for now it doesn't (it only supports raw resources) and\n // React Native's Image works fine with drawable resource names for\n // images.\n if (Platform.OS === 'android' && !uri.includes(':') && (meta.width || meta.height)) {\n asset.localUri = asset.uri;\n asset.downloaded = true;\n }\n\n Asset.byHash[meta.hash] = asset;\n return asset;\n }\n\n return Asset.fromMetadata(meta);\n }\n\n // @docsMissing\n static fromMetadata(meta: AssetMetadata): Asset {\n // The hash of the whole asset, not to be confused with the hash of a specific file returned\n // from `selectAssetSource`\n const metaHash = meta.hash;\n if (Asset.byHash[metaHash]) {\n return Asset.byHash[metaHash];\n }\n\n const { uri, hash } = selectAssetSource(meta);\n const asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash,\n uri,\n width: meta.width,\n height: meta.height,\n });\n Asset.byHash[metaHash] = asset;\n return asset;\n }\n\n // @docsMissing\n static fromURI(uri: string): Asset {\n if (Asset.byUri[uri]) {\n return Asset.byUri[uri];\n }\n\n // Possibly a Base64-encoded URI\n let type = '';\n if (uri.indexOf(';base64') > -1) {\n type = uri.split(';')[0].split('/')[1];\n } else {\n const extension = AssetUris.getFileExtension(uri);\n type = extension.startsWith('.') ? extension.substring(1) : extension;\n }\n\n const asset = new Asset({\n name: '',\n type,\n hash: null,\n uri,\n });\n\n Asset.byUri[uri] = asset;\n\n return asset;\n }\n\n // @needsAudit\n /**\n * Downloads the asset data to a local file in the device's cache directory. Once the returned\n * promise is fulfilled without error, the [`localUri`](#localuri) field of this asset points\n * to a local file containing the asset data. The asset is only downloaded if an up-to-date local\n * file for the asset isn't already present due to an earlier download. The downloaded `Asset`\n * will be returned when the promise is resolved.\n * @return Returns a Promise which fulfills with an `Asset` instance.\n */\n async downloadAsync(): Promise<this> {\n if (this.downloaded) {\n return this;\n }\n if (this.downloading) {\n await new Promise<void>((resolve, reject) => {\n this._downloadCallbacks.push({ resolve, reject });\n });\n return this;\n }\n this.downloading = true;\n\n try {\n if (Platform.OS === 'web') {\n if (ImageAssets.isImageType(this.type)) {\n const { width, height, name } = await ImageAssets.getImageInfoAsync(this.uri);\n this.width = width;\n this.height = height;\n this.name = name;\n } else {\n this.name = AssetUris.getFilename(this.uri);\n }\n }\n this.localUri = await downloadAsync(this.uri, this.hash, this.type);\n\n this.downloaded = true;\n this._downloadCallbacks.forEach(({ resolve }) => resolve());\n } catch (e) {\n this._downloadCallbacks.forEach(({ reject }) => reject(e));\n throw e;\n } finally {\n this.downloading = false;\n this._downloadCallbacks = [];\n }\n return this;\n }\n}\n"]}
|
|
@@ -7,9 +7,9 @@ export type ResolvedAssetSource = {
|
|
|
7
7
|
scale: number;
|
|
8
8
|
};
|
|
9
9
|
export default class AssetSourceResolver {
|
|
10
|
-
serverUrl
|
|
11
|
-
|
|
12
|
-
asset: PackagerAsset;
|
|
10
|
+
private readonly serverUrl;
|
|
11
|
+
private readonly jsbundleUrl;
|
|
12
|
+
readonly asset: PackagerAsset;
|
|
13
13
|
constructor(serverUrl: string | undefined | null, jsbundleUrl: string | undefined | null, asset: PackagerAsset);
|
|
14
14
|
isLoadedFromServer(): boolean;
|
|
15
15
|
isLoadedFromFileSystem(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetSourceResolver.d.ts","sourceRoot":"","sources":["../src/AssetSourceResolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAI5E,MAAM,MAAM,mBAAmB,GAAG;IAChC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAcF,MAAM,CAAC,OAAO,OAAO,mBAAmB;IACtC,
|
|
1
|
+
{"version":3,"file":"AssetSourceResolver.d.ts","sourceRoot":"","sources":["../src/AssetSourceResolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAI5E,MAAM,MAAM,mBAAmB,GAAG;IAChC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf,C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AAC,CAAC,CAAC,CAAC;YACnB,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import type { PackagerAsset } from '@react-native/assets-registry/registry';\nimport { Platform } from 'expo-modules-core';\nimport { PixelRatio } from 'react-native';\n\nexport type ResolvedAssetSource = {\n __packager_asset: boolean;\n width?: number;\n height?: number;\n uri: string;\n scale: number;\n};\n\n// Returns the Metro dev server-specific asset location.\nfunction getScaledAssetPath(asset): string {\n const scale = AssetSourceResolver.pickScale(asset.scales, PixelRatio.get());\n const scaleSuffix = scale === 1 ? '' : '@' + scale + 'x';\n const type = !asset.type ? '' : `.${asset.type}`;\n if (__DEV__) {\n return asset.httpServerLocation + '/' + asset.name + scaleSuffix + type;\n } else {\n return asset.httpServerLocation.replace(/\\.\\.\\//g, '_') + '/' + asset.name + scaleSuffix + type;\n }\n}\n\nexport default class AssetSourceResolver {\n private readonly serverUrl: string;\n // where the jsbundle is being run from\n // NOTE(EvanBacon): Never defined on web.\n private readonly jsbundleUrl: string | undefined | null;\n // the asset to resolve\n public readonly asset: PackagerAsset;\n\n constructor(\n serverUrl: string | undefined | null,\n jsbundleUrl: string | undefined | null,\n asset: PackagerAsset\n ) {\n this.serverUrl = serverUrl || 'https://expo.dev';\n this.jsbundleUrl = null;\n this.asset = asset;\n }\n\n // Always true for web runtimes\n isLoadedFromServer(): boolean {\n return true;\n }\n\n // Always false for web runtimes\n isLoadedFromFileSystem(): boolean {\n return false;\n }\n\n defaultAsset(): ResolvedAssetSource {\n return this.assetServerURL();\n }\n\n /**\n * @returns absolute remote URL for the hosted asset.\n */\n assetServerURL(): ResolvedAssetSource {\n const fromUrl = new URL(getScaledAssetPath(this.asset), this.serverUrl);\n fromUrl.searchParams.set('platform', Platform.OS);\n fromUrl.searchParams.set('hash', this.asset.hash);\n return this.fromSource(\n // Relative on web\n fromUrl.toString().replace(fromUrl.origin, '')\n );\n }\n\n fromSource(source: string): ResolvedAssetSource {\n return {\n __packager_asset: true,\n width: this.asset.width ?? undefined,\n height: this.asset.height ?? undefined,\n uri: source,\n scale: AssetSourceResolver.pickScale(this.asset.scales, PixelRatio.get()),\n };\n }\n\n static pickScale(scales: number[], deviceScale: number): number {\n for (let i = 0; i < scales.length; i++) {\n if (scales[i] >= deviceScale) {\n return scales[i];\n }\n }\n return scales[scales.length - 1] || 1;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetSources.d.ts","sourceRoot":"","sources":["../src/AssetSources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAQ5E,MAAM,MAAM,aAAa,GAAG,IAAI,CAC9B,aAAa,EACb,oBAAoB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAChF,GAAG;IACF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;
|
|
1
|
+
{"version":3,"file":"AssetSources.d.ts","sourceRoot":"","sources":["../src/AssetSources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAQ5E,MAAM,MAAM,aAAa,GAAG,IAAI,CAC9B,aAAa,EACb,oBAAoB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAChF,GAAG;IACF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,aAAa,GAAG,WAAW,CAuDlE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG9C;AAGD,wBAAgB,QAAQ,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAwBnD"}
|
package/build/AssetSources.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { Platform } from 'expo-modules-core';
|
|
2
2
|
import { PixelRatio, NativeModules } from 'react-native';
|
|
3
3
|
import AssetSourceResolver from './AssetSourceResolver';
|
|
4
|
-
import {
|
|
5
|
-
// Fast lookup check if asset map has any overrides in the manifest.
|
|
6
|
-
// This value will always be either null or an absolute URL, e.g. `https://expo.dev/`
|
|
7
|
-
const assetMapOverride = getManifest().assetMapOverride;
|
|
4
|
+
import { getManifest2, manifestBaseUrl } from './PlatformUtils';
|
|
8
5
|
/**
|
|
9
6
|
* Selects the best file for the given asset (ex: choosing the best scale for images) and returns
|
|
10
7
|
* a { uri, hash } pair for the specific asset file.
|
|
@@ -12,10 +9,6 @@ const assetMapOverride = getManifest().assetMapOverride;
|
|
|
12
9
|
* If the asset isn't an image with multiple scales, the first file is selected.
|
|
13
10
|
*/
|
|
14
11
|
export function selectAssetSource(meta) {
|
|
15
|
-
// Override with the asset map in manifest if available
|
|
16
|
-
if (assetMapOverride && assetMapOverride.hasOwnProperty(meta.hash)) {
|
|
17
|
-
meta = { ...meta, ...assetMapOverride[meta.hash] };
|
|
18
|
-
}
|
|
19
12
|
// This logic is based on that of AssetSourceResolver, with additional support for file hashes and
|
|
20
13
|
// explicitly provided URIs
|
|
21
14
|
const scale = AssetSourceResolver.pickScale(meta.scales, PixelRatio.get());
|
|
@@ -26,12 +19,6 @@ export function selectAssetSource(meta) {
|
|
|
26
19
|
if (uri) {
|
|
27
20
|
return { uri: resolveUri(uri), hash };
|
|
28
21
|
}
|
|
29
|
-
// Check if the assetUrl was overridden in the manifest
|
|
30
|
-
const assetUrlOverride = getManifest().assetUrlOverride;
|
|
31
|
-
if (assetUrlOverride) {
|
|
32
|
-
const uri = pathJoin(assetUrlOverride, hash);
|
|
33
|
-
return { uri: resolveUri(uri), hash };
|
|
34
|
-
}
|
|
35
22
|
const fileScale = scale === 1 ? '' : `@${scale}x`;
|
|
36
23
|
const fileExtension = meta.type ? `.${encodeURIComponent(meta.type)}` : '';
|
|
37
24
|
const suffix = `/${encodeURIComponent(meta.name)}${fileScale}${fileExtension}`;
|
|
@@ -49,10 +36,7 @@ export function selectAssetSource(meta) {
|
|
|
49
36
|
const manifest2 = getManifest2();
|
|
50
37
|
const devServerUrl = manifest2?.extra?.expoGo?.developer
|
|
51
38
|
? 'http://' + manifest2.extra.expoGo.debuggerHost
|
|
52
|
-
:
|
|
53
|
-
getManifest().developer
|
|
54
|
-
? getManifest().bundleUrl
|
|
55
|
-
: null;
|
|
39
|
+
: null;
|
|
56
40
|
if (devServerUrl) {
|
|
57
41
|
const baseUrl = new URL(meta.httpServerLocation + suffix, devServerUrl);
|
|
58
42
|
baseUrl.searchParams.set('platform', Platform.OS);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetSources.js","sourceRoot":"","sources":["../src/AssetSources.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEzD,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"AssetSources.js","sourceRoot":"","sources":["../src/AssetSources.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MA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AAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import type { PackagerAsset } from '@react-native/assets-registry/registry';\nimport { Platform } from 'expo-modules-core';\nimport { PixelRatio, NativeModules } from 'react-native';\n\nimport AssetSourceResolver from './AssetSourceResolver';\nimport { getManifest2, manifestBaseUrl } from './PlatformUtils';\n\n// @docsMissing\nexport type AssetMetadata = Pick<\n PackagerAsset,\n 'httpServerLocation' | 'name' | 'hash' | 'type' | 'scales' | 'width' | 'height'\n> & {\n uri?: string;\n fileHashes?: string[];\n fileUris?: string[];\n};\n\nexport type AssetSource = {\n uri: string;\n hash: string;\n};\n\n/**\n * Selects the best file for the given asset (ex: choosing the best scale for images) and returns\n * a { uri, hash } pair for the specific asset file.\n *\n * If the asset isn't an image with multiple scales, the first file is selected.\n */\nexport function selectAssetSource(meta: AssetMetadata): AssetSource {\n // This logic is based on that of AssetSourceResolver, with additional support for file hashes and\n // explicitly provided URIs\n const scale = AssetSourceResolver.pickScale(meta.scales, PixelRatio.get());\n const index = meta.scales.findIndex((s) => s === scale);\n const hash = meta.fileHashes ? meta.fileHashes[index] ?? meta.fileHashes[0] : meta.hash;\n\n // Allow asset processors to directly provide the URL to load\n const uri = meta.fileUris ? meta.fileUris[index] ?? meta.fileUris[0] : meta.uri;\n if (uri) {\n return { uri: resolveUri(uri), hash };\n }\n\n const fileScale = scale === 1 ? '' : `@${scale}x`;\n const fileExtension = meta.type ? `.${encodeURIComponent(meta.type)}` : '';\n const suffix = `/${encodeURIComponent(meta.name)}${fileScale}${fileExtension}`;\n const params = new URLSearchParams({\n platform: Platform.OS,\n hash: meta.hash,\n });\n\n // For assets with a specified absolute URL, we use the existing origin instead of prepending the\n // development server or production CDN URL origin\n if (/^https?:\\/\\//.test(meta.httpServerLocation)) {\n const uri = meta.httpServerLocation + suffix + '?' + params;\n return { uri, hash };\n }\n\n // For assets during development using manifest2, we use the development server's URL origin\n const manifest2 = getManifest2();\n\n const devServerUrl = manifest2?.extra?.expoGo?.developer\n ? 'http://' + manifest2.extra.expoGo.debuggerHost\n : null;\n if (devServerUrl) {\n const baseUrl = new URL(meta.httpServerLocation + suffix, devServerUrl);\n\n baseUrl.searchParams.set('platform', Platform.OS);\n baseUrl.searchParams.set('hash', meta.hash);\n return {\n uri: baseUrl.href,\n hash,\n };\n }\n\n // Temporary fallback for loading assets in Expo Go home\n if (NativeModules.ExponentKernel) {\n return { uri: `https://classic-assets.eascdn.net/~assets/${encodeURIComponent(hash)}`, hash };\n }\n\n // In correctly configured apps, we arrive here if the asset is locally available on disk due to\n // being managed by expo-updates, and `getLocalAssetUri(hash)` must return a local URI for this\n // hash. Since the asset is local, we don't have a remote URL and specify an invalid URL (an empty\n // string) as a placeholder.\n return { uri: '', hash };\n}\n\n/**\n * Resolves the given URI to an absolute URI. If the given URI is already an absolute URI, it is\n * simply returned. Otherwise, if it is a relative URI, it is resolved relative to the manifest's\n * base URI.\n */\nexport function resolveUri(uri: string): string {\n // `manifestBaseUrl` is always an absolute URL or `null`.\n return manifestBaseUrl ? new URL(uri, manifestBaseUrl).href : uri;\n}\n\n// A very cheap path canonicalization like path.join but without depending on a `path` polyfill.\nexport function pathJoin(...paths: string[]): string {\n // Start by simply combining paths, without worrying about \"..\" or \".\"\n const combined = paths\n .map((part, index) => {\n if (index === 0) {\n return part.trim().replace(/\\/*$/, '');\n }\n return part.trim().replace(/(^\\/*|\\/*$)/g, '');\n })\n .filter((part) => part.length > 0)\n .join('/')\n .split('/');\n\n // Handle \"..\" and \".\" in paths\n const resolved: string[] = [];\n for (const part of combined) {\n if (part === '..') {\n resolved.pop(); // Remove the last element from the result\n } else if (part !== '.') {\n resolved.push(part);\n }\n }\n\n return resolved.join('/');\n}\n"]}
|
package/build/AssetUris.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetUris.js","sourceRoot":"","sources":["../src/AssetUris.ts"],"names":[],"mappings":"AAA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ED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAmB;IACpD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;IAEvC,IAAI,YAAY,GAAG,SAAS,CAAC,QAAQ,CAAC;IACtC,+CAA+C;IAC/C,IAAI,YAAY,KAAK,MAAM,EAAE,CAAC;QAC5B,YAAY,GAAG,OAAO,CAAC;IACzB,CAAC;SAAM,IAAI,YAAY,KAAK,OAAO,EAAE,CAAC;QACpC,YAAY,GAAG,QAAQ,CAAC;IAC1B,CAAC;IACD,SAAS,CAAC,QAAQ,GAAG,YAAY,CAAC;IAElC,wDAAwD;IACxD,MAAM,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3F,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC;IAC/B,SAAS,CAAC,MAAM,GAAG,EAAE,CAAC;IACtB,SAAS,CAAC,IAAI,GAAG,EAAE,CAAC;IAEpB,4EAA4E;IAC5E,wEAAwE;IACxE,OAAO,SAAS,CAAC,QAAQ,KAAK,YAAY;QACxC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC;QAC1D,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC;AACrB,CAAC","sourcesContent":["export function getFilename(url: string): string {\n const { pathname, searchParams } = new URL(url, 'https://e');\n\n // When attached to a dev server, we use `unstable_path` to represent the file path. This ensures\n // the file name is not canonicalized by the browser.\n // NOTE(EvanBacon): This is technically not tied to `__DEV__` as it's possible to use this while bundling in production\n // mode.\n if (__DEV__) {\n if (searchParams.has('unstable_path')) {\n const encodedFilePath = decodeURIComponent(searchParams.get('unstable_path')!);\n return getBasename(encodedFilePath);\n }\n }\n\n return getBasename(pathname);\n}\n\nfunction getBasename(pathname: string): string {\n return pathname.substring(pathname.lastIndexOf('/') + 1);\n}\n\nexport function getFileExtension(url: string): string {\n const filename = getFilename(url);\n const dotIndex = filename.lastIndexOf('.');\n // Ignore leading dots for hidden files\n return dotIndex > 0 ? filename.substring(dotIndex) : '';\n}\n\n/**\n * Returns the base URL from a manifest's URL. For example, given a manifest hosted at\n * https://example.com/app/manifest.json, the base URL would be https://example.com/app/. Query\n * parameters and fragments also are removed.\n *\n * For an Expo-hosted project with a manifest hosted at https://exp.host/@user/project/index.exp, the\n * base URL would be https://exp.host/@user/project.\n *\n * We also normalize the \"exp\" protocol to \"http\" to handle internal URLs with the Expo schemes used\n * to tell the OS to open the URLs in the the Expo client.\n */\nexport function getManifestBaseUrl(manifestUrl: string): string {\n const urlObject = new URL(manifestUrl);\n\n let nextProtocol = urlObject.protocol;\n // Change the scheme to http(s) if it is exp(s)\n if (nextProtocol === 'exp:') {\n nextProtocol = 'http:';\n } else if (nextProtocol === 'exps:') {\n nextProtocol = 'https:';\n }\n urlObject.protocol = nextProtocol;\n\n // Trim filename, query parameters, and fragment, if any\n const directory = urlObject.pathname.substring(0, urlObject.pathname.lastIndexOf('/') + 1);\n urlObject.pathname = directory;\n urlObject.search = '';\n urlObject.hash = '';\n\n // The URL spec doesn't allow for changing the protocol to `http` or `https`\n // without a port set so instead, we'll just swap the protocol manually.\n return urlObject.protocol !== nextProtocol\n ? urlObject.href.replace(urlObject.protocol, nextProtocol)\n : urlObject.href;\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Downloads the asset from the given URL to a local cache and returns the local URL of the cached
|
|
3
|
+
* file.
|
|
4
|
+
*
|
|
5
|
+
* If there is already a locally cached file and its MD5 hash matches the given `md5Hash` parameter,
|
|
6
|
+
* if present, the remote asset is not downloaded. The `hash` property is included in Metro's asset
|
|
7
|
+
* metadata objects when this module's `hashAssetFiles` plugin is used, which is the typical way the
|
|
8
|
+
* `md5Hash` parameter of this function is provided.
|
|
9
|
+
*/
|
|
10
|
+
export declare function downloadAsync(url: string, md5Hash: string | null, type: string): Promise<string>;
|
|
11
|
+
//# sourceMappingURL=ExpoAsset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpoAsset.d.ts","sourceRoot":"","sources":["../src/ExpoAsset.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,MAAM,CAAC,CAEjB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { requireNativeModule } from 'expo-modules-core';
|
|
2
|
+
const AssetModule = requireNativeModule('ExpoAsset');
|
|
3
|
+
/**
|
|
4
|
+
* Downloads the asset from the given URL to a local cache and returns the local URL of the cached
|
|
5
|
+
* file.
|
|
6
|
+
*
|
|
7
|
+
* If there is already a locally cached file and its MD5 hash matches the given `md5Hash` parameter,
|
|
8
|
+
* if present, the remote asset is not downloaded. The `hash` property is included in Metro's asset
|
|
9
|
+
* metadata objects when this module's `hashAssetFiles` plugin is used, which is the typical way the
|
|
10
|
+
* `md5Hash` parameter of this function is provided.
|
|
11
|
+
*/
|
|
12
|
+
export async function downloadAsync(url, md5Hash, type) {
|
|
13
|
+
return AssetModule.downloadAsync(url, md5Hash, type);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=ExpoAsset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpoAsset.js","sourceRoot":"","sources":["../src/ExpoAsset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,MAAM,WAAW,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;AAErD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,GAAW,EACX,OAAsB,EACtB,IAAY;IAEZ,OAAO,WAAW,CAAC,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import { requireNativeModule } from 'expo-modules-core';\n\nconst AssetModule = requireNativeModule('ExpoAsset');\n\n/**\n * Downloads the asset from the given URL to a local cache and returns the local URL of the cached\n * file.\n *\n * If there is already a locally cached file and its MD5 hash matches the given `md5Hash` parameter,\n * if present, the remote asset is not downloaded. The `hash` property is included in Metro's asset\n * metadata objects when this module's `hashAssetFiles` plugin is used, which is the typical way the\n * `md5Hash` parameter of this function is provided.\n */\nexport async function downloadAsync(\n url: string,\n md5Hash: string | null,\n type: string\n): Promise<string> {\n return AssetModule.downloadAsync(url, md5Hash, type);\n}\n"]}
|