Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mediapicker

Package Overview
Dependencies
Maintainers
5
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mediapicker - npm Package Compare versions

Comparing version 5.3.3 to 5.3.4

lib/types/service/api.d.ts

11

lib/types/service/uploadService.d.ts

@@ -1,4 +0,4 @@

import { TokenSource } from '../domain/config';
import { EventEmitter2 as EventEmitter } from 'eventemitter2';
import { ResumableFile } from 'resumablejs';
import { TokenSource } from '../domain/config';
import { UploadParams } from '../domain/uploadParams';

@@ -16,8 +16,3 @@ export declare type FileFinalize = () => void;

private _uploadChunkUrl;
private _hashjobs;
private _hasherpool;
private _hasherrobin;
private _hashernum;
private _resumable;
private _hashGenerator;
private _token;

@@ -34,6 +29,2 @@ private _dropListener;

private _generateTarget(params);
private _createWorker(n);
private _dispatchJob(worker, jobid, chunkBlob);
private _generateHash(chunk);
private _generateHashIE(chunk);
private _pollFile(fileId, collection, callback);

@@ -40,0 +31,0 @@ private _onFilesAdded(resumableFiles);

@@ -1,2 +0,2 @@

import '!style-loader!css-loader!less-loader!./popup.less';
import '!style!css!less!./popup.less';
import { MediaLocalUpload } from './localUpload';

@@ -3,0 +3,0 @@ import { ModuleConfig } from '../domain/config';

@@ -1,2 +0,2 @@

import '!style-loader!css-loader!less-loader!./dropzone.less';
import '!style!css!less!./dropzone.less';
import { MediaLocalUpload } from './localUpload';

@@ -3,0 +3,0 @@ import { MediaPickerContext } from '../domain/context';

@@ -1,2 +0,2 @@

import '!style-loader!css-loader!less-loader!./popup.less';
import '!style!css!less!./popup.less';
import { MPComponent } from './component';

@@ -25,3 +25,3 @@ import { UploadParams } from '../domain/uploadParams';

init(): void;
show(): Promise<void>;
show(): Promise<undefined>;
cancel(uniqueIdentifier?: string): void;

@@ -28,0 +28,0 @@ teardown(): void;

@@ -10,7 +10,2 @@ export declare const ERROR_NAMES: {

};
export interface MediaErrorRecord {
fileId: string;
name: string;
description: string;
}
export declare class MediaError {

@@ -24,3 +19,3 @@ private _fileId;

readonly description: string;
toJSON(): MediaErrorRecord;
toJSON(): Object;
}

@@ -23,4 +23,4 @@ import { ResumableFile, ResumableChunk } from 'resumablejs';

readonly chunks: ResumableChunk[];
readonly raw: File | undefined;
readonly preview: File | undefined;
readonly raw: File;
readonly preview: File;
toJSON(): Object;

@@ -27,0 +27,0 @@ toPureJSON(): Object;

@@ -1,3 +0,3 @@

import '!style-loader!css-loader!less-loader!./aui-short.less';
import '!style-loader!css-loader!less-loader!./mp.less';
import '!style!css!less!./aui-short.less';
import '!style!css!less!./mp.less';
export declare function MediaPicker(componentName: string, ...options: Array<any>): any;

@@ -39,3 +39,3 @@ export interface InternalStorage {

}
declare const herment: (config: any) => any;
declare const herment: any;
export default herment;
import { UserEventName } from './tracker';
import { UserEventProperties } from './tracker';
export interface UserEventJSONRepresentation {
name: UserEventName;
properties: UserEventProperties;
}
export declare class UserEvent {

@@ -12,3 +8,6 @@ private _name;

constructor(name: UserEventName, properties: UserEventProperties);
toJSON(): UserEventJSONRepresentation;
toJSON(): {
name: string;
properties: UserEventProperties;
};
}

@@ -15,0 +14,0 @@ export declare class MediaPickerLoaded extends UserEvent {

@@ -37,3 +37,3 @@ import { EventEmitter2 as EventEmitter } from 'eventemitter2';

query: any;
setUploadParams(uploadParams: UploadParams): Promise<void>;
setUploadParams(uploadParams: UploadParams): Promise<undefined>;
giveReadGrants(fileId: string, granteeId: string): Promise<string>;

@@ -40,0 +40,0 @@ putFileIntoCollection(fileId: string, collectionName: string, occurrKey?: string): Promise<boolean>;

{
"name": "mediapicker",
"version": "5.3.3",
"version": "5.3.4",
"description": "Library for handling file uploads",

@@ -24,3 +24,3 @@ "main": "./lib/mediapicker.js",

"s3-upload": "npm run test && npm run build && ./node_modules/.bin/grunt s3",
"pub": "npm run build-local && npm run s3-upload && npm publish",
"pub": "npm run s3-upload && npm publish",
"release": "npm run test && npm run build && ./node_modules/.bin/grunt s3",

@@ -27,0 +27,0 @@ "ci-all": "npm run lint && npm run build-local && npm run test"

@@ -1,17 +0,20 @@

import {TokenSource} from '../domain/config';
import {Rusha} from 'rusha';
import {EventEmitter2 as EventEmitter} from 'eventemitter2';
import * as Resumable from 'resumablejs';
import {ResumableFile, ResumableChunk} from 'resumablejs';
import {handleError} from '../util/handleError';
import * as uuid from 'uuid';
import {MediaError, ERROR_NAMES} from '../domain/error';
import {UploadParams} from '../domain/uploadParams';
import {getTokenFromSource} from '../util/getTokenFromSource';
import {sliceByChunks} from '../util/sliceByChunks';
import {MutatedResumableChunk, SliceyFile, MutatedResumableFile} from '../util/typeExtensions';
import {MediaApiData} from './mediaAPI';
import axios from 'axios';
import {Promises} from '../util/promises';
import { EventEmitter2 as EventEmitter } from 'eventemitter2';
import { ResumableFile, ResumableChunk } from 'resumablejs';
import { TokenSource } from '../domain/config';
import { handleError } from '../util/handleError';
import { MediaError, ERROR_NAMES } from '../domain/error';
import { UploadParams } from '../domain/uploadParams';
import { getTokenFromSource } from '../util/getTokenFromSource';
import { sliceByChunks } from '../util/sliceByChunks';
import { MutatedResumableChunk, SliceyFile, MutatedResumableFile } from '../util/typeExtensions';
import { MediaApiData } from './mediaAPI';
import { Promises } from '../util/promises';
import { Hasher } from './hashing/hasher';
import { createHasher } from './hashing/hasherCreator';
type UploadId = string;

@@ -28,3 +31,2 @@ type ChunkId = string;

const MAX_RETRY_COUNT = 1;
const rushaWorkerInline = require('raw!../../node_modules/rusha/rusha.js');

@@ -54,17 +56,10 @@ const supportsModernUploader = () => {

private _uploadChunkUrl: string;
private _hashjobs: {[jobId: string]: ResumableChunk};
private _hasherpool: Array<Worker>;
private _hasherrobin: Array<number>;
private _hashernum: number;
private _resumable: Resumable;
private _hashGenerator: Function;
private _token: string;
private _dropListener: EventListener;
constructor(private _url: string,
private _clientId: string,
private _tokenSource: TokenSource,
private _uploadParams: UploadParams) {
private _clientId: string,
private _tokenSource: TokenSource,
private _uploadParams: UploadParams) {
super();

@@ -74,6 +69,2 @@

this._token = ''; // generated on every upload
this._hashjobs = {};
this._hasherpool = [];
this._hasherrobin = [];
this._hashernum = 3;
this.retry = 0;

@@ -89,3 +80,3 @@

this._hashGenerator = this._generateHash;
const hasher = createHasher();

@@ -109,10 +100,6 @@ this._resumable = new Resumable({

},
preprocess: (chunk) => this._hashGenerator(chunk),
preprocess: chunk => hasher.hash(chunk),
generateUniqueIdentifier: generateUniqueId
});
for (let i = 0; i < this._hashernum; i++) {
this._createWorker(i);
}
this._resumable.on('filesAdded', (files) => this._onFilesAdded(files));

@@ -191,76 +178,2 @@ this._resumable.on('chunkingComplete', (fileObj) => this._onChunkingComplete(fileObj));

private _createWorker(n: number): void {
this._hasherrobin[n] = 0;
const workerBlob = new Blob([rushaWorkerInline]);
const blobURL = window.URL.createObjectURL(workerBlob);
try {
this._hasherpool[n] = new Worker(blobURL);
this._hasherpool[n].addEventListener('message', (event) => {
this._hasherrobin[n]--;
const job = this._hashjobs[event.data.id];
delete this._hashjobs[event.data.id];
if (job) {
if (event.data.error) {
return this._generateHash(job);
} else {
(job as MutatedResumableChunk).hash = event.data.hash;
job.preprocessFinished();
}
}
});
} catch (err) {
this._hashGenerator = this._generateHashIE;
}
}
private _dispatchJob(worker: Worker, jobid: string, chunkBlob: Blob): void {
if (
navigator.userAgent.indexOf('Safari') > -1 &&
navigator.userAgent.indexOf('Chrome') === -1
) {
// Special fucking treat for Safari
const rd = new FileReader();
rd.readAsBinaryString(chunkBlob);
rd.onload = () => {
worker.postMessage({id: jobid, data: rd.result});
};
} else {
worker.postMessage({id: jobid, data: chunkBlob});
}
}
private _generateHash(chunk: ResumableChunk): void {
const file = chunk.fileObj.file;
const jobid = chunk.fileObj.fileName + chunk.fileObjSize + chunk.startByte;
const slice = file.slice || (file as SliceyFile).mozSlice || (file as SliceyFile).webkitSlice;
const chunkBlob = slice.call(file, chunk.startByte, chunk.endByte);
let hid = 0;
// find least active worker
for (let i = 0; i < this._hashernum; i++) {
if (this._hasherrobin[i] < this._hasherrobin[hid]) {
hid = i;
}
}
this._hasherrobin[hid]++;
this._hashjobs[jobid] = chunk;
this._dispatchJob(this._hasherpool[hid], jobid, chunkBlob);
}
private _generateHashIE(chunk: ResumableChunk): void {
const file = chunk.fileObj.file;
const slice = file.slice || (file as SliceyFile).mozSlice || (file as SliceyFile).webkitSlice;
const chunkBlob = slice.call(file, chunk.startByte, chunk.endByte);
const fileReader = new FileReader();
fileReader.onload = (event) => {
const arrayBuffer = (event.target as FileReader).result;
(chunk as MutatedResumableChunk).hash = new Rusha(4 * 1024 * 1024).digestFromArrayBuffer(arrayBuffer);
chunk.preprocessFinished();
};
fileReader.readAsArrayBuffer(chunkBlob);
}
private _pollFile(fileId: string, collection: string, callback: Function): void {

@@ -401,3 +314,3 @@ const collectionName = (collection) ? `&collection=${collection}` : '';

private _generateHeaders(): {[key: string]: string} {
private _generateHeaders(): { [key: string]: string } {
return {

@@ -493,29 +406,29 @@ 'Content-Type': 'application/json; charset=UTF-8',

this._regenerateUploadToken().then((token: string) => {
this._token = token;
this._token = token;
this._createUpload()
.then(uploadId => {
return this._appendChunksToUpload(uploadId, chunks, maxChunks)
.then(() => {
return this._createFileFromUpload(fileName, resumableFile.file.type, uploadId, (resumableFile as MutatedResumableFile).uploadParams.collection);
});
})
.then(fileId => {
if ((resumableFile as MutatedResumableFile).uploadParams.fetchMetadata !== false) {
this.emit('file-converting', resumableFile, fileId);
this._createUpload()
.then(uploadId => {
return this._appendChunksToUpload(uploadId, chunks, maxChunks)
.then(() => {
return this._createFileFromUpload(fileName, resumableFile.file.type, uploadId, (resumableFile as MutatedResumableFile).uploadParams.collection);
});
})
.then(fileId => {
if ((resumableFile as MutatedResumableFile).uploadParams.fetchMetadata !== false) {
this.emit('file-converting', resumableFile, fileId);
this._pollFile(fileId, (resumableFile as MutatedResumableFile).uploadParams.collection, (mediaApiData: MediaApiData) => {
this.emit('file-converted', resumableFile, mediaApiData);
});
} else {
this.emit('file-converted', resumableFile, {id: fileId});
}
});
}).catch(error => {
this._handleUploadError(ERROR_NAMES.OBJ_CREATE_FAIL, error, resumableFile.uniqueIdentifier)
.then(() => {
this._onFileSuccess(resumableFile);
}
);
});
this._pollFile(fileId, (resumableFile as MutatedResumableFile).uploadParams.collection, (mediaApiData: MediaApiData) => {
this.emit('file-converted', resumableFile, mediaApiData);
});
} else {
this.emit('file-converted', resumableFile, { id: fileId });
}
});
}).catch(error => {
this._handleUploadError(ERROR_NAMES.OBJ_CREATE_FAIL, error, resumableFile.uniqueIdentifier)
.then(() => {
this._onFileSuccess(resumableFile);
}
);
});
}

@@ -522,0 +435,0 @@

@@ -100,3 +100,3 @@ declare module 'resumablejs' {

**/
preprocess?: (chunk: ResumableChunk) => ResumableChunk;
preprocess?: (chunk: ResumableChunk) => void;
/**

@@ -103,0 +103,0 @@ * Override the function that generates unique identifiers for each file. (Default: null)

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc