-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
pr05 Typescript #3: Migrate client/utils folder #3553
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
base: develop
Are you sure you want to change the base?
Changes from all commits
a52d312
2480bd1
87adc72
9efdd25
462524c
8010af7
cb9ddc5
f7282c2
411eb4a
e7eaa2c
53962db
3efc164
fa6d69f
75b35a3
b7fb7a0
2440d6f
0a9af47
5302f54
2638c32
723cac3
e0cb6c7
0aab549
60f8a6e
04ca29a
e91000f
0713173
16d84e1
6957124
97754db
ed0c6f0
0b223df
a52372d
de6fc10
8061e09
058d155
34f0735
c6c7d40
2362807
1f5614c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ import { | |
} from './ide'; | ||
import { clearState, saveState } from '../../../persistState'; | ||
|
||
const ROOT_URL = getConfig('API_URL'); | ||
const ROOT_URL = getConfig('API_URL', { nullishString: true }); | ||
const S3_BUCKET_URL_BASE = getConfig('S3_BUCKET_URL_BASE'); | ||
const S3_BUCKET = getConfig('S3_BUCKET'); | ||
|
||
|
@@ -307,6 +307,8 @@ export function cloneProject(project) { | |
(file, callback) => { | ||
if ( | ||
file.url && | ||
S3_BUCKET && | ||
S3_BUCKET_URL_BASE && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this check for safety because I think
|
||
(file.url.includes(S3_BUCKET_URL_BASE) || | ||
file.url.includes(S3_BUCKET)) | ||
) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,11 @@ import { handleCreateFile } from './files'; | |
|
||
export const s3BucketHttps = | ||
getConfig('S3_BUCKET_URL_BASE') || | ||
`https://s3-${getConfig('AWS_REGION')}.amazonaws.com/${getConfig( | ||
'S3_BUCKET' | ||
)}/`; | ||
`https://s3-${getConfig('AWS_REGION', { | ||
nullishString: true | ||
})}.amazonaws.com/${getConfig('S3_BUCKET', { | ||
nullishString: true | ||
})}/`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const MAX_LOCAL_FILE_SIZE = 80000; // bytes, aka 80 KB | ||
|
||
function isS3Upload(file) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import prettyBytes from 'pretty-bytes'; | ||
|
||
import getConfig from '../../../utils/getConfig'; | ||
import { parseNumber } from '../../../utils/parseStringToType'; | ||
|
||
const limit = getConfig('UPLOAD_LIMIT') || 250000000; | ||
const limit = parseNumber(getConfig('UPLOAD_LIMIT')) || 250000000; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new Currently this file is still jsx so it would be ok to use the string version of this number, but it's not as safe |
||
const MAX_SIZE_B = limit; | ||
|
||
const formatPercent = (percent) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { getAllScriptOffsets, startTag } from './consoleUtils'; | ||
|
||
describe('getAllScriptOffsets', () => { | ||
// not sure how the line offset calculations have been formulated | ||
it('returns an empty array when no scripts are found', () => { | ||
const html = '<html><body><h1>No scripts here</h1></body></html>'; | ||
expect(getAllScriptOffsets(html)).toEqual([]); | ||
}); | ||
|
||
it('detects a single external script with @fs- path', () => { | ||
const html = ` | ||
<html> | ||
<head> | ||
<script src="${startTag}my-script.js"></script> | ||
</head> | ||
</html> | ||
`; | ||
const result = getAllScriptOffsets(html); | ||
expect(result.every(([offset, _]) => typeof offset === 'number')).toBe( | ||
true | ||
); | ||
expect(result.map(([_, name]) => name)).toEqual(['my-script']); | ||
}); | ||
|
||
it('detects multiple external scripts with @fs- paths', () => { | ||
const html = ` | ||
<script src="${startTag}one.js"></script> | ||
<script src="${startTag}two.js"></script> | ||
`; | ||
const result = getAllScriptOffsets(html); | ||
expect(result.every(([offset, _]) => typeof offset === 'number')).toBe( | ||
true | ||
); | ||
expect(result.map(([_, name]) => name)).toEqual(['one', 'two']); | ||
}); | ||
|
||
it('detects embedded scripts with crossorigin attribute', () => { | ||
const html = ` | ||
<html> | ||
<head> | ||
<script crossorigin=""></script> | ||
</head> | ||
</html> | ||
`; | ||
const result = getAllScriptOffsets(html); | ||
expect(result.every(([offset, _]) => typeof offset === 'number')).toBe( | ||
true | ||
); | ||
expect(result.map(([_, name]) => name)).toEqual(['index.html']); | ||
}); | ||
|
||
it('detects both @fs- scripts and embedded scripts together, ordering embedded scripts last', () => { | ||
const html = ` | ||
<script src="${startTag}abc.js"></script> | ||
<script crossorigin=""></script> | ||
<script src="${startTag}xyz.js"></script> | ||
`; | ||
const result = getAllScriptOffsets(html); | ||
expect(result.every(([offset, _]) => typeof offset === 'number')).toBe( | ||
true | ||
); | ||
expect(result.map(([_, name]) => name)).toEqual([ | ||
'abc', | ||
'xyz', | ||
'index.html' | ||
]); | ||
}); | ||
|
||
it('handles scripts with varying whitespace and newlines', () => { | ||
const html = ` | ||
<script src="${startTag}some-script.js"> | ||
</script> | ||
<script crossorigin=""> | ||
</script> | ||
`; | ||
const result = getAllScriptOffsets(html); | ||
expect(result.every(([offset, _]) => typeof offset === 'number')).toBe( | ||
true | ||
); | ||
expect(result.map(([_, name]) => name)).toEqual([ | ||
'some-script', | ||
'index.html' | ||
]); | ||
}); | ||
}); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { isMac } from './device'; | ||
|
||
describe('isMac', () => { | ||
const originalUserAgent = navigator.userAgent; | ||
|
||
afterEach(() => { | ||
// Restore the original userAgent after each test | ||
Object.defineProperty(navigator, 'userAgent', { | ||
value: originalUserAgent, | ||
configurable: true | ||
}); | ||
}); | ||
|
||
it('returns true when userAgent contains "Mac"', () => { | ||
Object.defineProperty(navigator, 'userAgent', { | ||
value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)', | ||
configurable: true | ||
}); | ||
expect(isMac()).toBe(true); | ||
}); | ||
|
||
it('returns false when userAgent does not contain "Mac"', () => { | ||
Object.defineProperty(navigator, 'userAgent', { | ||
value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', | ||
configurable: true | ||
}); | ||
expect(isMac()).toBe(false); | ||
}); | ||
|
||
it('returns false when navigator agent is null', () => { | ||
Object.defineProperty(navigator, 'userAgent', { | ||
value: null, | ||
configurable: true | ||
}); | ||
expect(isMac()).toBe(false); | ||
}); | ||
|
||
it('returns false when navigator agent is undefined', () => { | ||
Object.defineProperty(navigator, 'userAgent', { | ||
value: undefined, | ||
configurable: true | ||
}); | ||
expect(isMac()).toBe(false); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Checks if the user's OS is macOS based on the `navigator.userAgent` string. | ||
* This is the preferred method over `navigator.platform`, which is now deprecated: | ||
* - see https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform | ||
*/ | ||
export function isMac(): boolean { | ||
return typeof navigator?.userAgent === 'string' | ||
? navigator.userAgent.toLowerCase().includes('mac') | ||
: false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated this to return a
''
if no API_URL is found --> used in ln261 as a template literal so it was previously doingwhich would give: