Skip to content
Open
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
45 changes: 41 additions & 4 deletions assets/js/Services/Report.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Html from './Html'
import { MEDIA_FILE_TYPES } from './Settings'

/** With all of the data inconsistency between the old and new issues, we need to double-check some things:
* 1. If the issue is ACTIVE (found in the scan) but should be ignored, either because of the old
Expand Down Expand Up @@ -288,17 +289,19 @@ export function analyzeReport(report, ISSUE_STATE) {

const parser = new DOMParser()
const fileReferences = {}
const mediaReferences = {}

// Parse every document only once. Not every content item will have issues, but we need to parse each one anyway
// so we can scan them for references to course files.
Object.values(report.contentItems).forEach((contentItem) => {
contentItem.sections = getSectionsFromContentItem(report.contentSections, contentItem)
if(contentItem.body) {
let tempBody = parser.parseFromString(contentItem.body, 'text/html')

// Get all of the links to files in the content item.
let links = tempBody.getElementsByTagName('a')
const fileUrlPattern = /\/files\/(\d+)/

for(let i = 0; i < links.length; i++) {
let link = links[i]
let href = link.getAttribute('href')
Expand All @@ -321,6 +324,32 @@ export function analyzeReport(report, ISSUE_STATE) {
}
}

// Get all of the links to media files (audio, video) in the content item.
let mediaLinks = tempBody.getElementsByTagName("iframe");
const mediaFileUrlPattern = /\/media_attachments_iframe\/(\d+)/

for (let i = 0; i < mediaLinks.length; i++) {
let mediaLink = mediaLinks[i];
let src = mediaLink.getAttribute('src');
if (src) {
let mediaMatch = src.match(mediaFileUrlPattern);
if (mediaMatch && mediaMatch[1]) {
let mediaId = mediaMatch[1];
if (!mediaReferences[mediaId]) {
mediaReferences[mediaId] = [];
}
mediaReferences[mediaId].push({
contentItemId: contentItem.id,
contentItemBody: contentItem.body,
contentItemTitle: contentItem.title,
contentItemUrl: contentItem.url,
contentItemLmsId: contentItem.lmsContentId,
contentType: contentItem.contentType,
})
}
}
}

parsedDocuments[contentItem.id] = tempBody
usedContentItems[contentItem.id] = contentItem
}
Expand Down Expand Up @@ -406,9 +435,17 @@ export function analyzeReport(report, ISSUE_STATE) {
// references (like when the file is linked in the modules directly).
const lmsIdToFileMap = {}
report.files.forEach((file) => {
file.references = fileReferences[parseInt(file.lmsFileId)] || []
const sectionRefs = getSectionsFromFile(report.contentSections, file)
file.sectionRefs = sectionRefs ? sectionRefs : []
// Check file type to assign proper reference
if (MEDIA_FILE_TYPES.includes(file.fileType)) {
file.references = mediaReferences[parseInt(file.lmsFileId)] || []
const sectionRefs = getSectionsFromFile(report.contentSections, file)
file.sectionRefs = sectionRefs ? sectionRefs: []
}
else {
file.references = fileReferences[parseInt(file.lmsFileId)] || []
const sectionRefs = getSectionsFromFile(report.contentSections, file)
file.sectionRefs = sectionRefs ? sectionRefs : []
}
})

let tempFilesReviewed = 0
Expand Down
5 changes: 5 additions & 0 deletions assets/js/Services/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export const FILE_TYPES = [
'video',
]

export const MEDIA_FILE_TYPES = [
'audio',
'video',
]

export const FILE_TYPE_MAP = {
'pdf': FILE_FILTER.FILE_PDF,
'doc': FILE_FILTER.FILE_WORD,
Expand Down
Loading