Skip to content

Commit

Permalink
Merge pull request #201 from qgustavor/next
Browse files Browse the repository at this point in the history
Release - v1.3.1
  • Loading branch information
qgustavor authored Sep 6, 2024
2 parents 2a4ab7f + a086caf commit c645885
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
10 changes: 4 additions & 6 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ assignees: ''

---

<!--
IMPORTANT! Read this before continuing: https://github.com/qgustavor/mega/discussions/138
Please only post issues here. Since 1.0 was released other kind of messages such as questions and feature requests are now available in the discussions tab since it's better suited for that.
-->

**Describe the bug**
A clear and concise description of what the bug is.

<!-- If you have error stacks, include then here using ``` at the beginning and at the end -->

**To Reproduce**

Run this code in Node X.XX (or Deno/Firefox/Chromium/Cloudflare Workers/etc):
Expand All @@ -25,6 +21,8 @@ import { Storage } from 'megajs'
// edit this with your code
```

<!-- THIS IS IMPORTANT! It's really hard to debug an issue, sometimes impossible, without a reproducible example! -->

**Expected behavior**
A clear and concise description of what you expected to happen.

Expand Down
6 changes: 3 additions & 3 deletions lib/api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ class API extends EventEmitter {

pull (sn, retryno = 0) {
const controller = new AbortController()
const ssl = API.handleForceHttps() ? 1 : 0
this.sn = controller
this.fetch(`${this.gateway}sc?${new URLSearchParams({ sn, sid: this.sid })}`, {
this.fetch(`${this.gateway}sc?${new URLSearchParams({ sn, ssl, sid: this.sid })}`, {
method: 'POST',
signal: controller.signal
}).then(handleApiResponse).then(resp => {
Expand Down Expand Up @@ -199,8 +200,7 @@ class API extends EventEmitter {

static handleForceHttps (userOpt) {
if (userOpt != null) return userOpt
if (globalThis.Deno) return false
return process.env.IS_BROWSER_BUILD
return !!(globalThis.isSecureContext)
}

static getShouldAvoidUA () {
Expand Down
4 changes: 2 additions & 2 deletions lib/file.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -463,14 +463,14 @@ class File extends EventEmitter {

return this.children.reduce((results, entry) => {
if (entry.children) {
if (deep) return results.concat(entry.find(query, deep))
if (deep) return results.concat(entry.filter(query, deep))
return results
}
return query(entry) ? results.concat(entry) : results
}, [])
}

navigate (query, deep) {
navigate (query) {
if (!this.children) throw Error('You can only call .navigate on directories')

if (typeof query === 'string') {
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ How to contribute using pull requests:
- Fix issues
- Add features
- Refactor things
- Update TypeScript types if needed
- `npm run lint-fix` to fix common issues
- Build the bundled versions using `npm run build`
- Run at least Node tests using `npm test node` to test Node
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/test-runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ if (testedPlatform === 'node') {
const subprocess = cp.spawn('deno', [
'test',
'--allow-env=MEGA_MOCK_URL',
'--allow-net=' + gateway.slice(7),
'--allow-net=' + gateway.slice(7, -1),
...extraArguments
], {
cwd: buildDir,
Expand Down
6 changes: 6 additions & 0 deletions types/cjs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ declare namespace megajs {
inbox: MutableFile
mounts: MutableFile[]
files: { [id in string]: MutableFile }
filter (query: string | string[] | ((file: MutableFile) => boolean), deep?: boolean): MutableFile[]
find (query: string | string[] | ((file: MutableFile) => boolean), deep?: boolean): MutableFile | null
RSAPrivateKey: Array<number | number[]>
ready: Promise<this>
constructor (options: StorageOpts, cb?: errorCb)
Expand Down Expand Up @@ -66,6 +68,8 @@ declare namespace megajs {
sn?: AbortController
static globalApi?: API
static getGlobalApi (): API
static handleForceHttps (userOpt?: boolean): boolean
static getShouldAvoidUA (): boolean
constructor (keepalive: boolean, opts?: APIOpts)
close (): void
pull (sn: AbortController, retryno?: number): void
Expand Down Expand Up @@ -123,6 +127,7 @@ declare namespace megajs {
moveTo (target: File | string, cb?: (error: err, data?: any) => void): Promise<void>
upload (opts: uploadOpts | string, source?: BufferString, cb?: uploadCb): Writable
mkdir (opts: mkdirOpts | string, cb?: (error: err, file: MutableFile) => void): Promise<MutableFile>
navigate (query: string | string[]): MutableFile | undefined
uploadAttribute (type: uploadAttrType, data: Buffer, cb?: (error: err, file?: this) => void): Promise<this>
importFile (sharedFile: string | File, cb?: (error: err, file?: this) => void): Promise<MutableFile>
on (event: 'move', listener: (oldDir: File) => void): this
Expand Down Expand Up @@ -157,6 +162,7 @@ declare namespace megajs {
interface StorageOpts extends APIOpts {
email: string
password: BufferString
secondFactorCode?: string
autoload?: boolean
autologin?: boolean
keepalive?: boolean
Expand Down
6 changes: 6 additions & 0 deletions types/es.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export declare class Storage extends EventEmitter {
inbox: MutableFile
mounts: MutableFile[]
files: { [id in string]: MutableFile }
filter (query: string | string[] | ((file: MutableFile) => boolean), deep?: boolean): MutableFile[]
find (query: string | string[] | ((file: MutableFile) => boolean), deep?: boolean): MutableFile | null
RSAPrivateKey: Array<number | number[]>
ready: Promise<this>
constructor (options: StorageOpts, cb?: errorCb)
Expand Down Expand Up @@ -59,6 +61,8 @@ export declare class API extends EventEmitter {
sn?: AbortController
static globalApi?: API
static getGlobalApi (): API
static handleForceHttps (userOpt?: boolean): boolean
static getShouldAvoidUA (): boolean
constructor (keepalive: boolean, opts?: APIOpts)
close (): void
pull (sn: AbortController, retryno?: number): void
Expand Down Expand Up @@ -116,6 +120,7 @@ declare class MutableFile extends File {
moveTo (target: File | string, cb?: (error: err, data?: any) => void): Promise<void>
upload (opts: uploadOpts | string, source?: BufferString, cb?: uploadCb): Writable
mkdir (opts: mkdirOpts | string, cb?: (error: err, file: MutableFile) => void): Promise<MutableFile>
navigate (query: string | string[]): MutableFile | undefined
uploadAttribute (type: uploadAttrType, data: Buffer, cb?: (error: err, file?: this) => void): Promise<this>
importFile (sharedFile: string | File, cb?: (error: err, file?: this) => void): Promise<MutableFile>
on (event: 'move', listener: (oldDir: File) => void): this
Expand Down Expand Up @@ -149,6 +154,7 @@ type noop = () => void
interface StorageOpts extends APIOpts {
email: string
password: BufferString
secondFactorCode?: string
autoload?: boolean
autologin?: boolean
keepalive?: boolean
Expand Down

0 comments on commit c645885

Please sign in to comment.