Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ qiniu.compressImage(file, options).then(data => {
* config.region: 选择上传域名区域;当为 `null` 或 `undefined` 时,自动分析上传域名区域,当指定了 `uphost` 时,此设置项无效。
* config.retryCount: 上传自动重试次数(整体重试次数,而不是某个分片的重试次数);默认 3 次(即上传失败后最多重试两次)。
* config.concurrentRequestLimit: 分片上传的并发请求量,`number`,默认为3;因为浏览器本身也会限制最大并发量,所以最大并发量与浏览器有关。
* config.checkByServer: 是否开启服务端文件签名校验,为布尔值;开启后在文件上传时会计算本地的文件签名,服务端会根据本地的签名与接收到的数据的签名进行比对,如果不相同、则说明文件可能存在问题,此时会返回错误(`code`: 406),默认为 `false`,不开启。
* config.checkByServer: 是否开启服务端文件签名校验,为布尔值;开启后在文件上传时会计算本地的文件签名,服务端会根据本地的签名与接收到的数据的签名进行比对,如果不相同、则说明文件可能存在问题,此时会返回错误(`code`: 406),默认为 `true`,不开启。
* config.checkByMD5: 是否开启 `MD5` 校验,为布尔值;在断点续传时,开启 `MD5` 校验会将已上传的分片与当前分片进行 `MD5` 值比对,若不一致,则重传该分片,避免使用错误的分片。读取分片内容并计算 `MD5` 需要花费一定的时间,因此会稍微增加断点续传时的耗时,默认为 `false`,不开启。
* config.forceDirect: 是否上传全部采用直传方式,为布尔值;为 `true` 时则上传方式全部为直传 form 方式,禁用断点续传,默认 `false`。
* config.chunkSize: `number`,分片上传时每片的大小,必须为正整数,单位为 `MB`,且最大不能超过 1024,默认值 4。因为 chunk 数最大 10000,所以如果文件以你所设的 `chunkSize` 进行分片并且 chunk 数超过 10000,我们会把你所设的 `chunkSize` 扩大二倍,如果仍不符合则继续扩大,直到符合条件。
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "qiniu-js",
"jsName": "qiniu",
"version": "3.4.2",
"version": "3.4.3",
"private": false,
"description": "Javascript SDK for Qiniu Resource (Cloud) Storage AP",
"main": "lib/index.js",
Expand Down
1 change: 1 addition & 0 deletions site/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"root": true,
"extends": [
"@qiniu"
]
Expand Down
22 changes: 11 additions & 11 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"dev": "webpack serve --mode development --inline --hot --open",
"start": "webpack serve --mode development",
"build": "webpack --mode development",
"dev": "NODE_OPTIONS=--openssl-legacy-provider webpack serve --mode development --inline --hot --open",
"start": "NODE_OPTIONS=--openssl-legacy-provider webpack serve --mode development",
"build": "NODE_OPTIONS=--openssl-legacy-provider webpack --mode development",
"lint": "eslint --ext .tsx,.ts src/"
},
"license": "MIT",
"devDependencies": {
"@qiniu/eslint-config": "0.0.6-beta.7",
"@types/create-hmac": "^1.1.0",
"@types/react": "^17.0.5",
"@types/react-dom": "^17.0.5",
"@types/create-hmac": "^1.1.3",
"@types/react": "^18.3.0",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "~4.10.0",
"buffer": "^6.0.3",
"css-loader": "^5.2.4",
"esbuild-loader": "^2.13.1",
"eslint": "~7.2.0",
Expand All @@ -29,21 +30,20 @@
"html-webpack-plugin": "^5.3.1",
"less": "^4.1.1",
"less-loader": "^9.0.0",
"stream-browserify": "^3.0.0",
"style-loader": "^2.0.0",
"typescript": "4.1.5",
"url-loader": "^4.1.1",
"webpack": "^5.37.0",
"webpack-cli": "^4.7.0",
"webpack-dev-server": "^3.11.2",
"webpackbar": "^5.0.0-3",
"buffer": "^6.0.3",
"stream-browserify": "^3.0.0"
"webpackbar": "^5.0.0-3"
},
"dependencies": {
"byte-size": "^7.0.1",
"create-hmac": "^1.1.7",
"js-base64": "^3.7.2",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react": "^18.3.1",
"react-dom": "^18.3.1"
}
}
1 change: 1 addition & 0 deletions site/src/components/Queue/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react'

import type { UniqueFile } from '../SelectFile'

import { Item } from './item'
Expand Down
6 changes: 3 additions & 3 deletions site/src/components/Settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react'

import * as utils from '../../utils'

import { Input } from '../Input'
Expand All @@ -8,7 +9,6 @@ interface IProps { }

export function Settings(props: IProps) {
const setting = React.useMemo(() => utils.loadSetting(), [])

const [deadline, setDeadline] = React.useState<number>(0)
const [uphost, seUphost] = React.useState<string>(setting.uphost || '')
const [assessKey, setAssessKey] = React.useState<string>(setting.assessKey || '')
Expand All @@ -25,11 +25,11 @@ export function Settings(props: IProps) {
})
}, [assessKey, secretKey, bucketName, deadline, uphost])

React.useEffect(()=> {
React.useEffect(() => {
if (deadline > 0) return
// 基于当前时间加上 3600s
setDeadline(Math.floor(Date.now() / 1000) + 3600)
},[deadline])
}, [deadline])

return (
<div className={classnames.settings}>
Expand Down
18 changes: 13 additions & 5 deletions site/src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,19 @@ export function useUpload(file: File) {
// 获取 token
React.useEffect(() => {
const { assessKey, secretKey, bucketName, deadline } = loadSetting()
if (!assessKey || !secretKey || !bucketName || !deadline) {
if (token == null && (!assessKey || !secretKey || !bucketName || !deadline)) {
setError(new Error('请点开设置并输入必要的配置信息'))
return
}

// 线上应该使用服务端生成 token
setToken(generateUploadToken({ assessKey, secretKey, bucketName, deadline }))
}, [file])
if (token != null) return

// 确保所有必需的参数都存在后再调用 generateUploadToken
if (assessKey && secretKey && bucketName && deadline) {
setToken(generateUploadToken({ assessKey, secretKey, bucketName, deadline }))
}
}, [file, token])

// 创建上传任务
React.useEffect(() => {
Expand All @@ -90,11 +95,14 @@ export function useUpload(file: File) {
metadata: {
'x-qn-meta-test': 'tt',
'x-qn-meta-test1': '222',
'x-qn-meta-test2': '333',
'x-qn-meta-test2': '333'
}
},
{
checkByMD5: true,
// checkByMD5: true,
checkByServer: true,
chunkSize: 2,
concurrentRequestLimit: 3,
debugLogLevel: 'INFO',
uphost: uphost && uphost.split(',')
}
Expand Down
61 changes: 25 additions & 36 deletions site/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
"@typescript-eslint/parser" "~4.10.0"
eslint-config-airbnb "~18.2.0"

"@types/create-hmac@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@types/create-hmac/-/create-hmac-1.1.0.tgz#d5bc34b65aeaf8f7bbd4a064172ab48318763b63"
integrity sha512-BNYNdzdhOZZQWCOpwvIll3FSvgo3e55Y2M6s/jOY6TuOCwqt3cLmQsK4tSmJ5fayDot8EG4k3+hcZagfww9JlQ==
"@types/create-hmac@^1.1.3":
version "1.1.3"
resolved "https://mirrors.cloud.tencent.com/npm/@types/create-hmac/-/create-hmac-1.1.3.tgz#fba2fe41fb98d37b76da2ca5a7158dc7408727dc"
integrity sha512-oDDSoBrAfdEPQuBpQp14y/ygUVU1IC6gq8Arm8IPP8TRC11AnLLYmpE3VvNUhPK/Ax3USGDjdE1Sc1LCIpf0NQ==
dependencies:
"@types/node" "*"

Expand Down Expand Up @@ -138,27 +138,19 @@
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==

"@types/react-dom@^17.0.5":
version "17.0.5"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.5.tgz#df44eed5b8d9e0b13bb0cd38e0ea6572a1231227"
integrity sha512-ikqukEhH4H9gr4iJCmQVNzTB307kROe3XFfHAOTxOXPOw7lAoEXnM5KWTkzeANGL5Ce6ABfiMl/zJBYNi7ObmQ==
dependencies:
"@types/react" "*"
"@types/react-dom@^18.3.0":
version "18.3.7"
resolved "https://mirrors.cloud.tencent.com/npm/@types/react-dom/-/react-dom-18.3.7.tgz#b89ddf2cd83b4feafcc4e2ea41afdfb95a0d194f"
integrity sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==

"@types/react@*", "@types/react@^17.0.5":
version "17.0.5"
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.5.tgz#3d887570c4489011f75a3fc8f965bf87d09a1bea"
integrity sha512-bj4biDB9ZJmGAYTWSKJly6bMr4BLUiBrx9ujiJEoP9XIDY9CTaPGxE5QWN/1WjpPLzYF7/jRNnV2nNxNe970sw==
"@types/react@^18.3.0":
version "18.3.23"
resolved "https://mirrors.cloud.tencent.com/npm/@types/react/-/react-18.3.23.tgz#86ae6f6b95a48c418fecdaccc8069e0fbb63696a"
integrity sha512-/LDXMQh55EzZQ0uVAZmKKhfENivEvWz6E+EYzh+/MCjMhNsotd+ZHhBGIjFDTi6+fz0OhQQQLbTgdQIxxCsC0w==
dependencies:
"@types/prop-types" "*"
"@types/scheduler" "*"
csstype "^3.0.2"

"@types/scheduler@*":
version "0.16.1"
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.1.tgz#18845205e86ff0038517aab7a18a62a6b9f71275"
integrity sha512-EaCxbanVeyxDRTQBkdLb3Bvl/HK7PBK6UJjsSixB0iHKoWxE5uu2Q/DgtpOhPIojN0Zl1whvOd7PoHs2P0s5eA==

"@typescript-eslint/eslint-plugin@~4.10.0":
version "4.10.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.10.0.tgz#19ed3baf4bc4232c5a7fcd32eaca75c3a5baf9f3"
Expand Down Expand Up @@ -3839,27 +3831,25 @@ [email protected]:
iconv-lite "0.4.24"
unpipe "1.0.0"

react-dom@^17.0.2:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23"
integrity sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==
react-dom@^18.3.1:
version "18.3.1"
resolved "https://mirrors.cloud.tencent.com/npm/react-dom/-/react-dom-18.3.1.tgz#c2265d79511b57d479b3dd3fdfa51536494c5cb4"
integrity sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
scheduler "^0.20.2"
scheduler "^0.23.2"

react-is@^16.8.1:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==

react@^17.0.2:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"
integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==
react@^18.3.1:
version "18.3.1"
resolved "https://mirrors.cloud.tencent.com/npm/react/-/react-18.3.1.tgz#49ab892009c53933625bd16b2533fc754cab2891"
integrity sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

read-pkg-up@^2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -4121,13 +4111,12 @@ sax@^1.2.4:
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==

scheduler@^0.20.2:
version "0.20.2"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.2.tgz#4baee39436e34aa93b4874bddcbf0fe8b8b50e91"
integrity sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==
scheduler@^0.23.2:
version "0.23.2"
resolved "https://mirrors.cloud.tencent.com/npm/scheduler/-/scheduler-0.23.2.tgz#414ba64a3b282892e944cf2108ecc078d115cdc3"
integrity sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

schema-utils@^1.0.0:
version "1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/upload/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const DEFAULT_CHUNK_SIZE = 4 // 单位 MB

// code 信息地址 https://developer.qiniu.com/kodo/3928/error-responses
export const FREEZE_CODE_LIST = [0, 502, 503, 504, 599] // 将会冻结当前 host 的 code
export const RETRY_CODE_LIST = [...FREEZE_CODE_LIST, 612] // 会进行重试的 code
export const RETRY_CODE_LIST = [...FREEZE_CODE_LIST, 406] // 会进行重试的 code

/** 上传文件的资源信息配置 */
export interface Extra {
Expand Down
12 changes: 6 additions & 6 deletions src/utils/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('test config ', () => {
uphost: [],
retryCount: 3,
checkByMD5: false,
checkByServer: false,
checkByServer: true,
forceDirect: false,
useCdnDomain: true,
concurrentRequestLimit: 3,
Expand All @@ -24,7 +24,7 @@ describe('test config ', () => {
uphost: [],
retryCount: 3,
checkByMD5: false,
checkByServer: false,
checkByServer: true,
forceDirect: false,
useCdnDomain: true,
concurrentRequestLimit: 3,
Expand All @@ -40,7 +40,7 @@ describe('test config ', () => {
uphost: regionUphostMap[region.z0].cdnUphost,
retryCount: 3,
checkByMD5: false,
checkByServer: false,
checkByServer: true,
forceDirect: false,
useCdnDomain: true,
concurrentRequestLimit: 3,
Expand All @@ -55,7 +55,7 @@ describe('test config ', () => {
uphost: ['test'],
retryCount: 3,
checkByMD5: false,
checkByServer: false,
checkByServer: true,
forceDirect: false,
useCdnDomain: true,
concurrentRequestLimit: 3,
Expand All @@ -71,7 +71,7 @@ describe('test config ', () => {
uphost: ['test'],
retryCount: 3,
checkByMD5: false,
checkByServer: false,
checkByServer: true,
forceDirect: false,
useCdnDomain: true,
concurrentRequestLimit: 3,
Expand All @@ -87,7 +87,7 @@ describe('test config ', () => {
uphost: regionUphostMap[region.z0].srcUphost,
retryCount: 3,
checkByMD5: false,
checkByServer: false,
checkByServer: true,
forceDirect: false,
useCdnDomain: false,
concurrentRequestLimit: 3,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function normalizeUploadConfig(config?: Partial<Config>, logger?: Logger)
checkByMD5: false,
forceDirect: false,
useCdnDomain: true,
checkByServer: false,
checkByServer: true,
concurrentRequestLimit: 3,
chunkSize: DEFAULT_CHUNK_SIZE,

Expand Down