Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a way for business to be able to send attachments to clients #435

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions backend/src/components/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@ const HttpStatus = require('http-status-codes')

async function getFile(req, res) {
try {
let operation = `msdyn_richtextfiles(${req.params.fileId})/`
if (req.query.image) {
operation += 'msdyn_imageblob/$value?size=full'
let fileDataOperation = `msdyn_richtextfiles(${req.params.fileId})/`

if (req.query.image === 'true') {
fileDataOperation += 'msdyn_imageblob/$value?size=full'
} else {
operation += 'msdyn_fileblob'
fileDataOperation += 'msdyn_fileblob'
}
const response = await getOperation(operation)
return res.status(HttpStatus.OK).json(response?.value)
const fileDataResponse = await getOperation(fileDataOperation)

const fileDetailsOperation = `fileattachments?$filter=(_objectid_value eq ${req.params.fileId})`
const fileDetailsResponse = await getOperation(fileDetailsOperation)
const fileDetails = fileDetailsResponse?.value[0] || { mimetype: undefined, filename: undefined }

return res.status(HttpStatus.OK).json({
fileData: fileDataResponse?.value,
mimetype: fileDetails.mimetype,
filename: fileDetails.filename,
})
} catch (e) {
handleError(res, e)
}
Expand Down
41 changes: 36 additions & 5 deletions frontend/src/components/messages/RequestConversations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<span class="font-weight-bold">Sent:</span>
{{ format.formatDate(item.sentDate) }}
</div>
<div class="pt-1" v-html="item.message" />
<div class="pt-1" @click.capture="handlePdf" v-html="item.message" />
</v-col>
</v-row>
</template>
Expand Down Expand Up @@ -209,6 +209,16 @@ export default {
deriveFromDisplay(item) {
return item.ofmSourceSystem ? `${this.userInfo?.firstName ?? ''} ${this.userInfo?.lastName}` : OFM_PROGRAM
},
handlePdf(event) {
if (event.target.classList.contains('conversation-pdf')) {
fetch(event.target.dataset.link)
.then((res) => res.blob())
.then((blob) => {
const blobUrl = URL.createObjectURL(blob)
window.open(blobUrl)
})
}
},
async formatConversation() {
const parser = new DOMParser()
for (const conversation of this.assistanceRequestConversation) {
Expand All @@ -218,15 +228,36 @@ export default {
const matches = ID_REGEX.exec(img.getAttribute('src'))
if (matches) {
const fileId = matches[1]
const image = await FileService.getFile(fileId)
const imageType = deriveImageType(image)
img.setAttribute('src', `data:image/${imageType};base64,${image}`)
const imageFile = await FileService.getFile(fileId, true)
const imageType = deriveImageType(imageFile.fileData)
img.setAttribute('src', `data:image/${imageType};base64,${imageFile.fileData}`)
} else {
img.remove()
}
}

// Remove CRM links for now until we can support them
document.querySelectorAll('a[href*="/api/data"]').forEach((link) => link.remove())
const fileLinks = document.querySelectorAll('a[href*="/api/data"]')

for (const fileLink of fileLinks) {
const matches = ID_REGEX.exec(fileLink.dataset.value)
if (matches) {
const fileId = matches[1]
const file = await FileService.getFile(fileId)
const dataLink = `data:${file.mimetype};base64,${file.fileData}`

if (file.mimetype === 'application/pdf') {
fileLink.setAttribute('href', '#')
fileLink.classList.add('conversation-pdf')
fileLink.setAttribute('data-link', dataLink)
} else {
fileLink.setAttribute('href', dataLink)
fileLink.setAttribute('download', file.filename)
}
} else {
fileLink.remove()
}
}

// Update the message content
conversation.message = document.documentElement.innerHTML
Expand Down
Loading