-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from codelitdev/issue-127
Cloudfront compatible hosting
- Loading branch information
Showing
12 changed files
with
179 additions
and
72 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,30 +1,48 @@ | ||
export const appName = process.env.APP_NAME || "Cloud Upload Service"; | ||
export const dbConnectionString = process.env.DB_CONNECTION_STRING; | ||
// App config | ||
export const appName = process.env.APP_NAME || "MediaLit"; | ||
export const jwtSecret = process.env.JWT_SECRET || "r@nd0m1e"; | ||
export const jwtExpire = process.env.JWT_EXPIRES_IN || "1d"; | ||
export const mailHost = process.env.EMAIL_HOST; | ||
export const mailUser = process.env.EMAIL_USER; | ||
export const mailPass = process.env.EMAIL_PASS; | ||
export const mailFrom = process.env.EMAIL_FROM; | ||
export const mailPort = parseInt(process.env.EMAIL_PORT || "") || 587; | ||
export const tempFileDirForUploads = process.env.TEMP_FILE_DIR_FOR_UPLOADS; | ||
export const maxFileUploadSize = process.env.MAX_UPLOAD_SIZE || 2147483648; | ||
export const PRESIGNED_URL_VALIDITY_MINUTES = 5; | ||
export const PRESIGNED_URL_LENGTH = 100; | ||
export const MEDIA_ID_LENGTH = 40; | ||
export const APIKEY_RESTRICTION_REFERRER = "referrer"; | ||
export const APIKEY_RESTRICTION_IP = "ipaddress"; | ||
export const APIKEY_RESTRICTION_CUSTOM = "custom"; | ||
export const tempFileDirForUploads = process.env.TEMP_FILE_DIR_FOR_UPLOADS; | ||
export const maxFileUploadSize = process.env.MAX_UPLOAD_SIZE || 2147483648; | ||
export const imagePattern = /^image\/(jpe?g|png)$/; | ||
export const imagePatternIncludingGif = /^image\/(jpe?g|png|gif|webp)$/; | ||
export const videoPattern = /video/; | ||
export const thumbnailWidth = 120; | ||
export const thumbnailHeight = 69; | ||
export const numberOfRecordsPerPage = 10; | ||
|
||
// Database config | ||
export const dbConnectionString = process.env.DB_CONNECTION_STRING; | ||
|
||
// Mail config | ||
export const mailHost = process.env.EMAIL_HOST; | ||
export const mailUser = process.env.EMAIL_USER; | ||
export const mailPass = process.env.EMAIL_PASS; | ||
export const mailFrom = process.env.EMAIL_FROM; | ||
export const mailPort = parseInt(process.env.EMAIL_PORT || "") || 587; | ||
|
||
// AWS S3 config | ||
export const cloudEndpoint = process.env.CLOUD_ENDPOINT || ""; | ||
export const cloudRegion = process.env.CLOUD_REGION || ""; | ||
export const cloudKey = process.env.CLOUD_KEY || ""; | ||
export const cloudSecret = process.env.CLOUD_SECRET || ""; | ||
export const cloudBucket = process.env.CLOUD_BUCKET_NAME || ""; | ||
export const cdnEndpoint = process.env.CDN_ENDPOINT || ""; | ||
export const thumbnailWidth = 120; | ||
export const thumbnailHeight = 69; | ||
export const numberOfRecordsPerPage = 10; | ||
export const PRESIGNED_URL_VALIDITY_MINUTES = 5; | ||
export const PRESIGNED_URL_LENGTH = 100; | ||
export const MEDIA_ID_LENGTH = 40; | ||
export const CLOUD_PREFIX = process.env.CLOUD_PREFIX || ""; | ||
export const S3_ENDPOINT = process.env.S3_ENDPOINT || ""; | ||
|
||
// Cloudfront config | ||
export const USE_CLOUDFRONT = process.env.USE_CLOUDFRONT === "true"; | ||
export const CLOUDFRONT_ENDPOINT = process.env.CLOUDFRONT_ENDPOINT || ""; | ||
export const CLOUDFRONT_KEY_PAIR_ID = process.env.CLOUDFRONT_KEY_PAIR_ID || ""; | ||
export const CLOUDFRONT_PRIVATE_KEY = process.env.CLOUDFRONT_PRIVATE_KEY || ""; | ||
export const CDN_MAX_AGE = process.env.CDN_MAX_AGE | ||
? +process.env.CDN_MAX_AGE | ||
: 1000 * 60 * 60; // one hour | ||
|
||
export const ENDPOINT = USE_CLOUDFRONT ? CLOUDFRONT_ENDPOINT : S3_ENDPOINT; |
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,17 +1,15 @@ | ||
import { CLOUD_PREFIX } from "../../config/constants"; | ||
|
||
interface GenerateKeyProps { | ||
mediaId: string; | ||
type: "main" | "thumb"; | ||
extension?: string; | ||
} | ||
|
||
export default function generateKey({ | ||
mediaId, | ||
type, | ||
extension, | ||
}: GenerateKeyProps): string { | ||
return `${CLOUD_PREFIX ? `${CLOUD_PREFIX}/` : ""}${mediaId}/${type}.${ | ||
type === "thumb" ? "webp" : extension | ||
}`; | ||
access, | ||
filename, | ||
}: { | ||
mediaId: string; | ||
access: "private" | "public"; | ||
filename: string; | ||
}): string { | ||
return `${ | ||
CLOUD_PREFIX ? `${CLOUD_PREFIX}/` : "" | ||
}${access}/${mediaId}/${filename}`; | ||
} |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
import path from "path"; | ||
import { ENDPOINT, CLOUD_PREFIX } from "../../config/constants"; | ||
import { Media } from "@medialit/models"; | ||
|
||
const prefix = CLOUD_PREFIX ? `${CLOUD_PREFIX}/` : ""; | ||
|
||
export function getMainFileUrl(media: Media) { | ||
return `${ENDPOINT}/${prefix}public/${media.mediaId}/main${path.extname( | ||
media.fileName | ||
)}`; | ||
} | ||
|
||
export function getThumbnailUrl(mediaId: string) { | ||
return `${ENDPOINT}/${prefix}public/${mediaId}/thumb.webp`; | ||
} |
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
Oops, something went wrong.