-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vapt: merge back into tracking branch (#1195)
* fix(approvedreviewredirect): removed redir for github users on error * fix(media): disallow file extension change (#1173) * refactor(imagepreviewcard): shift util method into separate file * refactor(mediacreation/update): prevent users from being able to change file ext * fix(files): update utilmethod * Fix: remove . when no file extension (#1184) * Fix: remove . when no file extension * feat: restriction file extension modification for media upload * Fix: restrict duplicate file names * Fix: media schema * Nit: add comment for behaviour of fileExt --------- Co-authored-by: seaerchin <[email protected]> Co-authored-by: seaerchin <[email protected]>
- Loading branch information
1 parent
9fcaf84
commit d7e47fd
Showing
8 changed files
with
88 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import _ from "lodash" | ||
|
||
export const getFileExt = (mediaUrl: string): string | undefined => { | ||
// NOTE: If it starts with data, the image is within a private repo. | ||
// Hence, we will extract the portion after the specifier | ||
// till the terminating semi-colon for use as the extension | ||
if (mediaUrl.startsWith("data:image/")) { | ||
return _.takeWhile(mediaUrl.slice(11), (char) => char !== ";").join("") | ||
} | ||
|
||
// Otherwise, this will point to a publicly accessible github url | ||
return mediaUrl.split(".").pop()?.split("?").shift() | ||
} | ||
|
||
/** | ||
* @precondition this function must only be called on a qualified filename. | ||
* Ie, calling this function on a `data:...` is invalid and the function will return | ||
* erroneous info. | ||
* | ||
* This function also assumes that the file is not nested within any directory | ||
* @param name the qualified filename of the data | ||
* @returns | ||
*/ | ||
export const getFileName = (name: string): string => { | ||
return name.split(".").slice(0, -1).join(".") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters