Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release - v1.3.1 #201

Merged
merged 24 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4afa9d7
Improve bug report template
qgustavor Jun 29, 2024
230d11a
Merge pull request #200 from qgustavor/bug-report-improvement
qgustavor Jun 29, 2024
27d18dc
Fix typo
qgustavor Jun 29, 2024
030bfaa
Merge pull request #202 from qgustavor/bug-report-improvement
qgustavor Jun 29, 2024
2ebdca4
secondFactorCode type was missing in Storage constructor (TS)
xmok Sep 3, 2024
76cd6e2
Merge pull request #204 from xmok/add-missing-2fa-type
qgustavor Sep 3, 2024
e00b9b2
find,fiter,navigate (need to revisit navigate)
xmok Sep 4, 2024
65e1889
update find and filter return types
xmok Sep 4, 2024
b13e47a
update find and filter query return type
xmok Sep 4, 2024
d48277b
update navigate return type
xmok Sep 4, 2024
96241d9
update find
xmok Sep 4, 2024
635d588
wait the filter ought to return array
xmok Sep 4, 2024
a82861b
Merge pull request #206 from xmok/add-missing-ts-types-in-storage
qgustavor Sep 5, 2024
4b7637b
Fix Deno tests
qgustavor Sep 5, 2024
d79318d
Merge pull request #207 from qgustavor/fix-deno-test
qgustavor Sep 5, 2024
767245b
Add a note about updating TypeScript types
qgustavor Sep 5, 2024
aec3d00
Merge pull request #208 from qgustavor/readme-ts-types
qgustavor Sep 5, 2024
b1ed12d
Update TS types with missing static methods
qgustavor Sep 6, 2024
5acf2aa
Handle `ssl` parameter in API's pull method
qgustavor Sep 6, 2024
d41b273
Fix .filter implementation
qgustavor Sep 6, 2024
c8b6395
Merge pull request #210 from qgustavor/fix-filter-method
qgustavor Sep 6, 2024
9913351
Merge pull request #209 from qgustavor/fixing-issue-205
qgustavor Sep 6, 2024
cb60c5a
Simplify handleForceHttps
qgustavor Sep 6, 2024
a086caf
Merge pull request #211 from qgustavor/simplify-handle-force-https
qgustavor Sep 6, 2024
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
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