Fixed scaling of images. Fixed server.js issues for production
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<babeledit_project version="1.2" be_version="2.6.1">
|
<babeledit_project be_version="2.6.1" version="1.2">
|
||||||
<!--
|
<!--
|
||||||
|
|
||||||
BabelEdit project file
|
BabelEdit project file
|
||||||
@@ -18,6 +18,110 @@
|
|||||||
<folder_node>
|
<folder_node>
|
||||||
<name>translation</name>
|
<name>translation</name>
|
||||||
<children>
|
<children>
|
||||||
|
<folder_node>
|
||||||
|
<name>documents</name>
|
||||||
|
<children>
|
||||||
|
<folder_node>
|
||||||
|
<name>errors</name>
|
||||||
|
<children>
|
||||||
|
<concept_node>
|
||||||
|
<name>getpresignurl</name>
|
||||||
|
<definition_loaded>false</definition_loaded>
|
||||||
|
<description></description>
|
||||||
|
<comment></comment>
|
||||||
|
<default_text></default_text>
|
||||||
|
<translations>
|
||||||
|
<translation>
|
||||||
|
<language>en-US</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>es-MX</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>fr-CA</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
</translations>
|
||||||
|
</concept_node>
|
||||||
|
<concept_node>
|
||||||
|
<name>insert</name>
|
||||||
|
<definition_loaded>false</definition_loaded>
|
||||||
|
<description></description>
|
||||||
|
<comment></comment>
|
||||||
|
<default_text></default_text>
|
||||||
|
<translations>
|
||||||
|
<translation>
|
||||||
|
<language>en-US</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>es-MX</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>fr-CA</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
</translations>
|
||||||
|
</concept_node>
|
||||||
|
</children>
|
||||||
|
</folder_node>
|
||||||
|
<folder_node>
|
||||||
|
<name>labels</name>
|
||||||
|
<children>
|
||||||
|
<concept_node>
|
||||||
|
<name>upload</name>
|
||||||
|
<definition_loaded>false</definition_loaded>
|
||||||
|
<description></description>
|
||||||
|
<comment></comment>
|
||||||
|
<default_text></default_text>
|
||||||
|
<translations>
|
||||||
|
<translation>
|
||||||
|
<language>en-US</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>es-MX</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>fr-CA</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
</translations>
|
||||||
|
</concept_node>
|
||||||
|
</children>
|
||||||
|
</folder_node>
|
||||||
|
<folder_node>
|
||||||
|
<name>successes</name>
|
||||||
|
<children>
|
||||||
|
<concept_node>
|
||||||
|
<name>insert</name>
|
||||||
|
<definition_loaded>false</definition_loaded>
|
||||||
|
<description></description>
|
||||||
|
<comment></comment>
|
||||||
|
<default_text></default_text>
|
||||||
|
<translations>
|
||||||
|
<translation>
|
||||||
|
<language>en-US</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>es-MX</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>fr-CA</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
</translations>
|
||||||
|
</concept_node>
|
||||||
|
</children>
|
||||||
|
</folder_node>
|
||||||
|
</children>
|
||||||
|
</folder_node>
|
||||||
<folder_node>
|
<folder_node>
|
||||||
<name>general</name>
|
<name>general</name>
|
||||||
<children>
|
<children>
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ export default function JobDetailCardsCustomerComponent({ loading, data }) {
|
|||||||
<CardTemplate
|
<CardTemplate
|
||||||
loading={loading}
|
loading={loading}
|
||||||
title={t("jobs.labels.cards.customer")}
|
title={t("jobs.labels.cards.customer")}
|
||||||
extraLink={data?.owner ? `/manage/owners/${data?.owner?.id}` : null}
|
extraLink={data?.owner ? `/manage/owners/${data?.owner?.id}` : null}>
|
||||||
>
|
|
||||||
{data ? (
|
{data ? (
|
||||||
<span>
|
<span>
|
||||||
<div>{`${data?.pit_owner_first_name ??
|
<div>{`${data?.pit_owner_first_name ??
|
||||||
@@ -25,7 +24,7 @@ export default function JobDetailCardsCustomerComponent({ loading, data }) {
|
|||||||
</a>
|
</a>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
<div>{`${data?.owner.preferred_contact ?? ""}`}</div>
|
<div>{`${data?.owner?.preferred_contact ?? ""}`}</div>
|
||||||
</span>
|
</span>
|
||||||
) : null}
|
) : null}
|
||||||
</CardTemplate>
|
</CardTemplate>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export default function JobsDocumentsContainer({ jobId }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<JobDocuments
|
<JobDocuments
|
||||||
data={data}
|
data={data.documents}
|
||||||
jobId={jobId}
|
jobId={jobId}
|
||||||
shopId={
|
shopId={
|
||||||
shopData.data?.bodyshops[0]?.id
|
shopData.data?.bodyshops[0]?.id
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Upload, Modal, Icon, Button } from "antd";
|
import { Upload, Modal, Icon, notification } from "antd";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import "./jobs-documents.styles.scss";
|
import "./jobs-documents.styles.scss";
|
||||||
import Resizer from "react-image-file-resizer";
|
import Resizer from "react-image-file-resizer";
|
||||||
//import { Resizer } from "../../utils/resizer";
|
import { useMutation } from "react-apollo";
|
||||||
|
import { INSERT_NEW_DOCUMENT } from "../../graphql/documents.queries";
|
||||||
|
|
||||||
function getBase64(file) {
|
function getBase64(file) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -16,11 +17,25 @@ function getBase64(file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function JobsDetailPage({ shopId, jobId, loading, data }) {
|
function JobsDetailPage({ shopId, jobId, loading, data }) {
|
||||||
//const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const [insertNewDocument] = useMutation(INSERT_NEW_DOCUMENT);
|
||||||
|
|
||||||
|
console.log("data", data);
|
||||||
|
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
previewVisible: false,
|
previewVisible: false,
|
||||||
previewImage: "",
|
previewImage: "",
|
||||||
|
|
||||||
|
fl: data.reduce((acc, value) => {
|
||||||
|
acc.push({
|
||||||
|
uid: value.id,
|
||||||
|
url: value.url,
|
||||||
|
name: value.name,
|
||||||
|
status: "done"
|
||||||
|
});
|
||||||
|
return acc;
|
||||||
|
}, []),
|
||||||
|
|
||||||
fileList: [
|
fileList: [
|
||||||
{
|
{
|
||||||
uid: "-1",
|
uid: "-1",
|
||||||
@@ -41,24 +56,22 @@ function JobsDetailPage({ shopId, jobId, loading, data }) {
|
|||||||
console.log("handleUpload Props:", ev);
|
console.log("handleUpload Props:", ev);
|
||||||
Resizer.imageFileResizer(
|
Resizer.imageFileResizer(
|
||||||
ev.file,
|
ev.file,
|
||||||
3000,
|
3500,
|
||||||
3000,
|
3500,
|
||||||
"JPEG",
|
"JPEG",
|
||||||
85,
|
75,
|
||||||
0,
|
0,
|
||||||
uri => {
|
uri => {
|
||||||
let file = new File([uri], ev.file.name, {
|
let file = new File([uri], ev.file.name, {});
|
||||||
//type: ev.file.type,
|
file.uid = ev.file.uid;
|
||||||
uid: ev.file.uid
|
|
||||||
});
|
|
||||||
|
|
||||||
// Split the filename to get the name and type
|
// Split the filename to get the name and type
|
||||||
let fileName = file.name;
|
let fileName = file.name;
|
||||||
let fileType = file.type;
|
let fileType = file.type;
|
||||||
console.log("Preparing the upload ");
|
let key = `${shopId}/${jobId}/${fileName}`;
|
||||||
|
//URL is using the proxy set in pacakges.json.
|
||||||
axios
|
axios
|
||||||
.post("/sign_s3", {
|
.post("/sign_s3", {
|
||||||
fileName: `${shopId}/${jobId}/${fileName}`,
|
fileName: key,
|
||||||
fileType
|
fileType
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
@@ -66,8 +79,6 @@ function JobsDetailPage({ shopId, jobId, loading, data }) {
|
|||||||
var signedRequest = returnData.signedRequest;
|
var signedRequest = returnData.signedRequest;
|
||||||
var url = returnData.url;
|
var url = returnData.url;
|
||||||
setState({ ...state, url: url });
|
setState({ ...state, url: url });
|
||||||
console.log("Recieved a signed request " + signedRequest);
|
|
||||||
|
|
||||||
// Put the fileType in the headers for the upload
|
// Put the fileType in the headers for the upload
|
||||||
var options = {
|
var options = {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -79,16 +90,40 @@ function JobsDetailPage({ shopId, jobId, loading, data }) {
|
|||||||
.put(signedRequest, file, options)
|
.put(signedRequest, file, options)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
console.log("Response from s3", result);
|
console.log("Response from s3", result);
|
||||||
|
|
||||||
|
insertNewDocument({
|
||||||
|
variables: {
|
||||||
|
docInput: [
|
||||||
|
{
|
||||||
|
jobid: jobId,
|
||||||
|
uploaded_by: "patrick@bodyshop.app",
|
||||||
|
url,
|
||||||
|
thumb_url: url
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}).then(r => {
|
||||||
|
console.log(r);
|
||||||
|
notification["success"]({
|
||||||
|
message: t("documents.successes.insert")
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
setState({ ...state, success: true });
|
setState({ ...state, success: true });
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log("Inside Error here.", error);
|
console.log("Error uploading to S3", error);
|
||||||
alert("ERROR " + JSON.stringify(error));
|
notification["error"]({
|
||||||
|
message: t("documents.errors.insert") + JSON.stringify(error)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log("Outside Error here.", error);
|
console.log("Outside Error here.", error);
|
||||||
alert(JSON.stringify(error));
|
notification["error"]({
|
||||||
|
message:
|
||||||
|
t("documents.errors.getpresignurl") + JSON.stringify(error)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
"blob"
|
"blob"
|
||||||
@@ -115,7 +150,7 @@ function JobsDetailPage({ shopId, jobId, loading, data }) {
|
|||||||
const uploadButton = (
|
const uploadButton = (
|
||||||
<div>
|
<div>
|
||||||
<Icon type='plus' />
|
<Icon type='plus' />
|
||||||
<div className='ant-upload-text'>Upload</div>
|
<div className='ant-upload-text'>{t("documents.labels.upload")}</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -123,11 +158,6 @@ function JobsDetailPage({ shopId, jobId, loading, data }) {
|
|||||||
<div className='clearfix'>
|
<div className='clearfix'>
|
||||||
<Upload
|
<Upload
|
||||||
customRequest={handleUpload}
|
customRequest={handleUpload}
|
||||||
data={file => ({
|
|
||||||
photoCotent: file, // file is currently uploading pictures
|
|
||||||
photoWidth: file.height, // Get the width and height of the picture by handleBeforeUpload
|
|
||||||
photoHeight: file.width
|
|
||||||
})}
|
|
||||||
accept='.pdf,.jpg,.jpeg'
|
accept='.pdf,.jpg,.jpeg'
|
||||||
listType='picture-card'
|
listType='picture-card'
|
||||||
fileList={fileList}
|
fileList={fileList}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export const GET_DOCUMENTS_BY_JOB = gql`
|
|||||||
|
|
||||||
export const INSERT_NEW_DOCUMENT = gql`
|
export const INSERT_NEW_DOCUMENT = gql`
|
||||||
mutation INSERT_NEW_DOCUMENT($docInput: [documents_insert_input!]!) {
|
mutation INSERT_NEW_DOCUMENT($docInput: [documents_insert_input!]!) {
|
||||||
insert_ducments(objects: $docInput) {
|
insert_documents(objects: $docInput) {
|
||||||
returning {
|
returning {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ function JobsDetailPage({ match, location }) {
|
|||||||
const [selectedTab, setSelectedTab] = useState(hash ? hash : "#lines");
|
const [selectedTab, setSelectedTab] = useState(hash ? hash : "#lines");
|
||||||
if (loading) return <SpinComponent />;
|
if (loading) return <SpinComponent />;
|
||||||
if (error) return <AlertComponent message={error.message} type='error' />;
|
if (error) return <AlertComponent message={error.message} type='error' />;
|
||||||
console.log("selectedTab", selectedTab);
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Row>
|
<Row>
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
{
|
{
|
||||||
"translation": {
|
"translation": {
|
||||||
|
"documents": {
|
||||||
|
"errors": {
|
||||||
|
"getpresignurl": "Error obtaining presigned URL for document. ",
|
||||||
|
"insert": "Unable to upload file."
|
||||||
|
},
|
||||||
|
"labels": {
|
||||||
|
"upload": "Upload"
|
||||||
|
},
|
||||||
|
"successes": {
|
||||||
|
"insert": "Uploaded document successfully. "
|
||||||
|
}
|
||||||
|
},
|
||||||
"general": {
|
"general": {
|
||||||
"labels": {
|
"labels": {
|
||||||
"in": "In",
|
"in": "In",
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
{
|
{
|
||||||
"translation": {
|
"translation": {
|
||||||
|
"documents": {
|
||||||
|
"errors": {
|
||||||
|
"getpresignurl": "Error al obtener la URL prescrita para el documento.",
|
||||||
|
"insert": "Incapaz de cargar el archivo."
|
||||||
|
},
|
||||||
|
"labels": {
|
||||||
|
"upload": "Subir"
|
||||||
|
},
|
||||||
|
"successes": {
|
||||||
|
"insert": "Documento cargado con éxito."
|
||||||
|
}
|
||||||
|
},
|
||||||
"general": {
|
"general": {
|
||||||
"labels": {
|
"labels": {
|
||||||
"in": "en",
|
"in": "en",
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
{
|
{
|
||||||
"translation": {
|
"translation": {
|
||||||
|
"documents": {
|
||||||
|
"errors": {
|
||||||
|
"getpresignurl": "Erreur lors de l'obtention de l'URL présignée pour le document.",
|
||||||
|
"insert": "Incapable de télécharger le fichier."
|
||||||
|
},
|
||||||
|
"labels": {
|
||||||
|
"upload": "Télécharger"
|
||||||
|
},
|
||||||
|
"successes": {
|
||||||
|
"insert": "Document téléchargé avec succès."
|
||||||
|
}
|
||||||
|
},
|
||||||
"general": {
|
"general": {
|
||||||
"labels": {
|
"labels": {
|
||||||
"in": "dans",
|
"in": "dans",
|
||||||
|
|||||||
26
s3upload.js
26
s3upload.js
@@ -45,3 +45,29 @@ exports.sign_s3 = (req, res) => {
|
|||||||
res.json({ success: true, data: { returnData } });
|
res.json({ success: true, data: { returnData } });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.get_s3 = (req, res) => {
|
||||||
|
const s3 = new aws.S3(); // Create a new instance of S3
|
||||||
|
const fileName = req.body.fileName;
|
||||||
|
//const fileType = req.body.fileType;
|
||||||
|
// Set up the payload of what we are sending to the S3 api
|
||||||
|
const s3Params = {
|
||||||
|
Bucket: S3_BUCKET,
|
||||||
|
Key: fileName,
|
||||||
|
Expires: 500
|
||||||
|
};
|
||||||
|
// Make a request to the S3 API to get a signed URL which we can use to upload our file
|
||||||
|
s3.getSignedUrl("getObject", s3Params, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
res.json({ success: false, error: err });
|
||||||
|
}
|
||||||
|
// Data payload of what we are sending back, the url of the signedRequest and a URL where we can access the content after its saved.
|
||||||
|
const returnData = {
|
||||||
|
signedRequest: data,
|
||||||
|
url: `https://${S3_BUCKET}.s3.amazonaws.com/${fileName}`
|
||||||
|
};
|
||||||
|
// Send it all back
|
||||||
|
res.json({ success: true, data: { returnData } });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
28
server.js
28
server.js
@@ -6,8 +6,8 @@ const compression = require("compression");
|
|||||||
var enforce = require("express-sslify");
|
var enforce = require("express-sslify");
|
||||||
if (process.env.NODE_ENV !== "production") require("dotenv").config();
|
if (process.env.NODE_ENV !== "production") require("dotenv").config();
|
||||||
|
|
||||||
const https = require('https');
|
const https = require("https");
|
||||||
const fs = require('fs');
|
const fs = require("fs");
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = process.env.PORT || 5000;
|
const port = process.env.PORT || 5000;
|
||||||
@@ -32,17 +32,29 @@ if (process.env.NODE_ENV === "production") {
|
|||||||
|
|
||||||
var s3upload = require("./s3upload");
|
var s3upload = require("./s3upload");
|
||||||
app.post("/sign_s3", s3upload.sign_s3);
|
app.post("/sign_s3", s3upload.sign_s3);
|
||||||
|
app.get("/sign_s3", s3upload.get_s3);
|
||||||
|
|
||||||
app.get("/test", function(req, res) {
|
app.get("/test", function(req, res) {
|
||||||
res.json({ success: true });
|
res.json({ success: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
https.createServer({
|
if (process.env.NODE_ENV === "production") {
|
||||||
key: fs.readFileSync('./key.pem'),
|
app.listen(port, error => {
|
||||||
cert: fs.readFileSync('./cert.pem'),
|
if (error) throw error;
|
||||||
passphrase: 'Wl0d8k@!'
|
console.log("Server running on port " + port);
|
||||||
}, app)
|
});
|
||||||
.listen(5000);
|
} else {
|
||||||
|
https
|
||||||
|
.createServer(
|
||||||
|
{
|
||||||
|
key: fs.readFileSync("./key.pem"),
|
||||||
|
cert: fs.readFileSync("./cert.pem"),
|
||||||
|
passphrase: "Wl0d8k@!"
|
||||||
|
},
|
||||||
|
app
|
||||||
|
)
|
||||||
|
.listen(port);
|
||||||
|
}
|
||||||
|
|
||||||
// app.listen(port, error => {
|
// app.listen(port, error => {
|
||||||
// if (error) throw error;
|
// if (error) throw error;
|
||||||
|
|||||||
Reference in New Issue
Block a user