fix: Should not get fake uploading url in demo (#79)
* fix not getting fake uploading url in demo * use internal service endpoint env * update internal svc endpoint
This commit is contained in:
@ -61,10 +61,10 @@ export function pdfAttachmentsRouter() {
|
||||
uploadFileData.id,
|
||||
fileName
|
||||
)
|
||||
const uploadSignedUrl =
|
||||
env.server.apiEnv === 'prod'
|
||||
? await generateUploadSignedUrl(uploadFilePathName, contentType)
|
||||
: 'http://localhost:3000/uploads/' + uploadFilePathName
|
||||
const uploadSignedUrl = await generateUploadSignedUrl(
|
||||
uploadFilePathName,
|
||||
contentType
|
||||
)
|
||||
res.send({
|
||||
id: uploadFileData.id,
|
||||
url: uploadSignedUrl,
|
||||
@ -117,10 +117,10 @@ export function pdfAttachmentsRouter() {
|
||||
return res.status(400).send('BAD REQUEST')
|
||||
}
|
||||
|
||||
const uploadFileDetails =
|
||||
env.server.apiEnv === 'prod'
|
||||
? await getStorageFileDetails(uploadFileId, uploadFile.fileName)
|
||||
: { md5Hash: '', size: 0 }
|
||||
const uploadFileDetails = await getStorageFileDetails(
|
||||
uploadFileId,
|
||||
uploadFile.fileName
|
||||
)
|
||||
const uploadFileHash = uploadFileDetails.md5Hash
|
||||
const pageType = PageType.File
|
||||
|
||||
@ -141,16 +141,10 @@ export function pdfAttachmentsRouter() {
|
||||
return res.status(400).send('BAD REQUEST')
|
||||
}
|
||||
|
||||
const uploadFileUrlOverride =
|
||||
env.server.apiEnv === 'prod'
|
||||
? await makeStorageFilePublic(
|
||||
uploadFileData.id,
|
||||
uploadFileData.fileName
|
||||
)
|
||||
: 'http://localhost:3000/uploads/' +
|
||||
uploadFileData.id +
|
||||
'/' +
|
||||
uploadFileData.fileName
|
||||
const uploadFileUrlOverride = await makeStorageFilePublic(
|
||||
uploadFileData.id,
|
||||
uploadFileData.fileName
|
||||
)
|
||||
|
||||
const link = await kx.transaction(async (tx) => {
|
||||
const articleRecord = await models.article.create(articleToSave, tx)
|
||||
|
||||
@ -18,6 +18,10 @@ export const generateUploadSignedUrl = async (
|
||||
filePathName: string,
|
||||
contentType: string
|
||||
): Promise<string> => {
|
||||
if (env.dev.isLocal) {
|
||||
return 'http://localhost:3000/uploads/' + filePathName
|
||||
}
|
||||
|
||||
// These options will allow temporary uploading of file with requested content type
|
||||
const options: GetSignedUrlConfig = {
|
||||
version: 'v4',
|
||||
@ -53,6 +57,10 @@ export const makeStorageFilePublic = async (
|
||||
id: string,
|
||||
fileName: string
|
||||
): Promise<string> => {
|
||||
if (env.dev.isLocal) {
|
||||
return 'http://localhost:3000/public/' + id + '/' + fileName
|
||||
}
|
||||
|
||||
// Makes the file public
|
||||
const filePathName = generateUploadFilePathName(id, fileName)
|
||||
await storage.bucket(bucketName).file(filePathName).makePublic()
|
||||
@ -65,6 +73,13 @@ export const getStorageFileDetails = async (
|
||||
id: string,
|
||||
fileName: string
|
||||
): Promise<{ md5Hash: string; fileUrl: string }> => {
|
||||
if (env.dev.isLocal) {
|
||||
return {
|
||||
md5Hash: 'some_md5_hash',
|
||||
fileUrl: 'http://localhost:3000/public/' + id + '/' + fileName,
|
||||
}
|
||||
}
|
||||
|
||||
const filePathName = generateUploadFilePathName(id, fileName)
|
||||
const file = storage.bucket(bucketName).file(filePathName)
|
||||
const [metadata] = await file.getMetadata()
|
||||
|
||||
@ -42,11 +42,11 @@ const getUploadIdAndSignedUrl = async (
|
||||
email,
|
||||
}
|
||||
|
||||
if (process.env.REST_BACKEND_ENDPOINT === undefined) {
|
||||
if (process.env.INTERNAL_SVC_ENDPOINT === undefined) {
|
||||
throw new Error('REST_BACKEND_ENDPOINT is not defined')
|
||||
}
|
||||
const response = await axios.post(
|
||||
`${process.env.REST_BACKEND_ENDPOINT}/svc/pdf-attachments/upload`,
|
||||
`${process.env.INTERNAL_SVC_ENDPOINT}svc/pdf-attachments/upload`,
|
||||
data,
|
||||
{
|
||||
headers: {
|
||||
@ -85,11 +85,11 @@ const createArticle = async (
|
||||
}
|
||||
const auth = await signToken(email, process.env.JWT_SECRET)
|
||||
|
||||
if (process.env.REST_BACKEND_ENDPOINT === undefined) {
|
||||
if (process.env.INTERNAL_SVC_ENDPOINT === undefined) {
|
||||
throw new Error('REST_BACKEND_ENDPOINT is not defined')
|
||||
}
|
||||
return axios.post(
|
||||
`${process.env.REST_BACKEND_ENDPOINT}/svc/pdf-attachments/create-article`,
|
||||
`${process.env.INTERNAL_SVC_ENDPOINT}svc/pdf-attachments/create-article`,
|
||||
data,
|
||||
{
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user