-
-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b139d77
commit 9428f8a
Showing
8 changed files
with
70 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import { URL } from 'url'; | ||
import path from 'path'; | ||
import { replaceSuffix } from '@teable/core'; | ||
import { baseConfig } from '../configs/base.config'; | ||
|
||
export const getFullStorageUrl = (url: string) => { | ||
const storagePrefix = baseConfig().storagePrefix; | ||
return new URL(url, storagePrefix).href; | ||
return path.join(storagePrefix, url); | ||
}; | ||
|
||
export const replaceStorageUrl = (originalUrl: string) => { | ||
const storagePrefix = baseConfig().storagePrefix; | ||
return replaceSuffix(originalUrl, storagePrefix); | ||
}; |
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,11 @@ | ||
export const replaceSuffix = (originalUrl: string, storagePrefix: string) => { | ||
const original = new URL(originalUrl); | ||
const suffix = new URL(storagePrefix); | ||
|
||
const suffixPath = suffix.pathname.endsWith('/') ? suffix.pathname : suffix.pathname + '/'; | ||
const originalPath = original.pathname.startsWith('/') | ||
? original.pathname.slice(1) | ||
: original.pathname; | ||
|
||
return `${suffix.origin}${suffixPath}${originalPath}${original.search}${original.hash}`; | ||
}; |