Commit a0c02023 authored by hewenhao's avatar hewenhao

feat: init

parents
module.exports = {
root: true,
rules: {
'prettier/prettier': 0,
"eqeqeq": 2,
"comma-dangle": 0,
"curly": 0,
"no-console": 1,
"no-debugger": 1,
"no-extra-semi": 2,
"no-extra-parens": 1,
"no-extra-boolean-cast": 1,
"no-cond-assign": 2,
"no-irregular-whitespace": 2,
"no-undef": 0,
"no-unused-vars": 0,
"semi": 2,
"semi-spacing": 2,
"valid-jsdoc": [
1,
{
"requireReturn": false,
"requireParamDescription": false,
"requireReturnDescription": false
}
],
"radix": 0
},
"parser": "babel-eslint"
};
.imdone
testconfig
ReactNativeBlobUtilTest/
test/test-server/public/*
!test/test-server/public/github.png
# OSX
#
.DS_Store
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace
/iOS/pods
Podfile*
contents.xcworkspacedata
# VSCode
#
.vscode
# Android/IJ
#
.idea
.gradle
local.properties
# node.js
#
node_modules/
npm-debug.log
# BUCK
buck-out/
\.buckd/
android/app/libs
android/keystores/debug.keystore
/ios/ReactNativeBlobUtil.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
\ No newline at end of file
MIT License
Copyright (c) 2017 xeiyan@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
This diff is collapsed.
// Copyright 2016 wkh237@github. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
import { NativeModules, Platform } from 'react-native';
const ReactNativeBlobUtil = NativeModules.ReactNativeBlobUtil;
/**
* Send an intent to open the file.
* @param {string} path Path of the file to be open.
* @param {string} mime MIME type string
* @param {string} chooserTitle for chooser, if not set the chooser won't be displayed (see https://developer.android.com/reference/android/content/Intent.html#createChooser(android.content.Intent,%20java.lang.CharSequence))
* @return {Promise}
*/
function actionViewIntent(path, mime, chooserTitle) {
if(typeof chooserTitle === 'undefined') chooserTitle = null;
if(Platform.OS === 'android')
return ReactNativeBlobUtil.actionViewIntent(path, mime, chooserTitle);
else
return Promise.reject('ReactNativeBlobUtil.android.actionViewIntent only supports Android.');
}
function getContentIntent(mime) {
if(Platform.OS === 'android')
return ReactNativeBlobUtil.getContentIntent(mime);
else
return Promise.reject('ReactNativeBlobUtil.android.getContentIntent only supports Android.');
}
function addCompleteDownload(config) {
if(Platform.OS === 'android')
return ReactNativeBlobUtil.addCompleteDownload(config);
else
return Promise.reject('ReactNativeBlobUtil.android.addCompleteDownload only supports Android.');
}
function getSDCardDir() {
if(Platform.OS === 'android')
return ReactNativeBlobUtil.getSDCardDir();
else
return Promise.reject('ReactNativeBlobUtil.android.getSDCardDir only supports Android.');
}
function getSDCardApplicationDir() {
if(Platform.OS === 'android')
return ReactNativeBlobUtil.getSDCardApplicationDir();
else
return Promise.reject('ReactNativeBlobUtil.android.getSDCardApplicationDir only supports Android.');
}
export default {
actionViewIntent,
getContentIntent,
addCompleteDownload,
getSDCardDir,
getSDCardApplicationDir,
};
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
repositories {
mavenCentral()
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
// Android JSC is installed from npm
url "$rootDir/../node_modules/jsc-android/dist"
}
google()
}
buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
// ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
if (project == rootProject) {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
}
}
}
android {
compileSdkVersion safeExtGet('compileSdkVersion', 30)
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 30)
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
productFlavors {
}
}
dependencies {
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
implementation 'org.apache.commons:commons-lang3:3.0'
}
afterEvaluate { project ->
// do this only when building this lib alone as a root project
if (project != rootProject) {
return
}
// some Gradle build hooks ref:
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
classpath += files(android.libraryVariants.collect { variant ->
variant.javaCompileProvider.get().classpath.files
})
}
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
classifier = 'javadoc'
from androidJavadoc.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
android.libraryVariants.all { variant ->
def name = variant.name.capitalize()
def javaCompileTask = variant.javaCompileProvider.get()
task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
from javaCompileTask.destinationDir
}
}
artifacts {
archives androidSourcesJar
archives androidJavadocJar
}
publishing {
publications {
mavenJava(MavenPublication) {
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
artifactId packageJson.name
groupId = "com.ReactNativeBlobUtil"
version = packageJson.version
pom {
name = packageJson.title
description = packageJson.description
url = packageJson.repository.baseUrl
licenses {
license {
name = packageJson.license
url = packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
distribution = 'repo'
}
}
developers {
developer {
id = packageJson.author.username
name = packageJson.author.name
}
}
}
}
}
repositories {
maven {
url = "file://${projectDir}/../android/maven"
}
}
}
}
\ No newline at end of file
android.enableJetifier=true
android.useAndroidX=true
\ No newline at end of file
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/xeiyan/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ReactNativeBlobUtil">
<!-- Required to download files from Google Play -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Required to keep CPU alive while downloading files
(NOT to keep screen awake) -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Required to poll the state of the network connection
and respond to changes -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Required to check whether Wi-Fi is enabled -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Required to read and write the expansion files on shared storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to read and write the expansion files on shared storage for Android 11-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- Required to to download files without a notification-->
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION"/>
<application android:label="@string/app_name">
<provider
android:name="com.ReactNativeBlobUtil.Utils.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
</application>
</manifest>
package com.ReactNativeBlobUtil;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import java.util.Locale;
class ReactNativeBlobUtilConfig {
public Boolean fileCache;
public Boolean transformFile;
public String path;
public String appendExt;
public ReadableMap addAndroidDownloads;
public Boolean trusty;
public Boolean wifiOnly = false;
public String key;
public String mime;
public Boolean auto;
public Boolean overwrite = true;
public long timeout = 60000;
public Boolean increment = false;
public Boolean followRedirect = true;
public ReadableArray binaryContentTypes = null;
ReactNativeBlobUtilConfig(ReadableMap options) {
if (options == null)
return;
this.fileCache = options.hasKey("fileCache") && options.getBoolean("fileCache");
this.transformFile = options.hasKey("transformFile") ? options.getBoolean("transformFile") : false;
this.path = options.hasKey("path") ? options.getString("path") : null;
this.appendExt = options.hasKey("appendExt") ? options.getString("appendExt") : "";
this.trusty = options.hasKey("trusty") && options.getBoolean("trusty");
this.wifiOnly = options.hasKey("wifiOnly") && options.getBoolean("wifiOnly");
if (options.hasKey("addAndroidDownloads")) {
this.addAndroidDownloads = options.getMap("addAndroidDownloads");
}
if (options.hasKey("binaryContentTypes"))
this.binaryContentTypes = options.getArray("binaryContentTypes");
if (this.path != null && path.toLowerCase(Locale.ROOT).contains("?append=true")) {
this.overwrite = false;
}
if (options.hasKey("overwrite"))
this.overwrite = options.getBoolean("overwrite");
if (options.hasKey("followRedirect")) {
this.followRedirect = options.getBoolean("followRedirect");
}
this.key = options.hasKey("key") ? options.getString("key") : null;
this.mime = options.hasKey("contentType") ? options.getString("contentType") : null;
this.increment = options.hasKey("increment") && options.getBoolean("increment");
this.auto = options.hasKey("auto") && options.getBoolean("auto");
if (options.hasKey("timeout")) {
this.timeout = options.getInt("timeout");
}
}
}
package com.ReactNativeBlobUtil;
public class ReactNativeBlobUtilConst {
public static final String EVENT_UPLOAD_PROGRESS = "ReactNativeBlobUtilProgress-upload";
public static final String EVENT_PROGRESS = "ReactNativeBlobUtilProgress";
public static final String EVENT_HTTP_STATE = "ReactNativeBlobUtilState";
public static final String EVENT_MESSAGE = "ReactNativeBlobUtilMessage";
public static final String FILE_PREFIX = "ReactNativeBlobUtil-file://";
public static final String CONTENT_PREFIX = "ReactNativeBlobUtil-content://";
public static final String FILE_PREFIX_BUNDLE_ASSET = "bundle-assets://";
public static final String FILE_PREFIX_CONTENT = "content://";
public static final String DATA_ENCODE_URI = "uri";
public static final String RNFB_RESPONSE_BASE64 = "base64";
public static final String RNFB_RESPONSE_UTF8 = "utf8";
public static final String RNFB_RESPONSE_PATH = "path";
public static final Integer GET_CONTENT_INTENT = 99900;
}
package com.ReactNativeBlobUtil;
public class ReactNativeBlobUtilFileTransformer {
public interface FileTransformer {
public byte[] onWriteFile(byte[] data);
public byte[] onReadFile(byte[] data);
}
public static ReactNativeBlobUtilFileTransformer.FileTransformer sharedFileTransformer;
}
\ No newline at end of file
package com.ReactNativeBlobUtil;
import androidx.annotation.NonNull;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ReactNativeBlobUtilPackage implements ReactPackage {
@NonNull
@Override
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new ReactNativeBlobUtil(reactContext));
return modules;
}
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
@NonNull
@Override
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
package com.ReactNativeBlobUtil;
/**
* Created by wkh237 on 2016/9/24.
*/
public class ReactNativeBlobUtilProgressConfig {
enum ReportType {
Upload,
Download
}
private long lastTick = 0;
private int tick = 0;
private int count = -1;
private int interval = -1;
private boolean enable = false;
private ReportType type = ReportType.Download;
ReactNativeBlobUtilProgressConfig(boolean report, int interval, int count, ReportType type) {
this.enable = report;
this.interval = interval;
this.type = type;
this.count = count;
}
public boolean shouldReport(float progress) {
boolean checkCount = true;
if (count > 0 && progress > 0)
checkCount = Math.floor(progress * count) > tick;
boolean result = (System.currentTimeMillis() - lastTick > interval) && enable && checkCount;
if (result) {
tick++;
lastTick = System.currentTimeMillis();
}
return result;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment