コード例 #1
0
ファイル: api.js プロジェクト: Orodan/Hilary-jitsi-fork
        ContentDAO.Content.getContent(contentRevisionId.contentId, function(err, content) {
            if (err) {
                return callback(err);
            }

            // Ensure the revision exists
            ContentDAO.Revisions.getRevision(contentRevisionId.revisionId, function(err, revision) {
                if (err) {
                    return callback(err);
                }

                var mediaCoreConfig = MediaCoreUtil.getConfig(content.tenant.alias);

                // Get the thumbnail data from MediaCore
                var getThumbsUrl = util.format('/api2/media/%s/thumbs', mediaCoreId);
                MediaCoreUtil.signedRequest(content.tenant.alias, 'get', getThumbsUrl, null, null, function(err, res, body) {
                    if (err) {
                        return callback(err);
                    } else if (res.statusCode !== 200) {
                        log().error({'code': res.statusCode, 'body': body}, 'An unexpected error occurred communicating with MediaCore');
                        return callback({'code': 500, 'msg': util.format('There was an unexpected error communicating with the media server. Code: %s', res.statusCode)});
                    }

                    try {
                        body = JSON.parse(body);
                    } catch (parseErr) {
                        log().error({
                            'err': parseErr,
                            'mediaCoreId': mediaCoreId,
                            'body': body
                        }, 'Error parsing MediaCore response as JSON');
                        return callback({'code': 500, 'msg': 'Error parsing MediaCore response as JSON'});
                    }

                    var thumbnailUri = 'remote:' + body.sizes.l;
                    var previewMetadata = {
                        'smallUri': 'remote:' + body.sizes.l,
                        'mediumUri': 'remote:' + body.sizes['720p'],
                        'largeUri': 'remote:' + body.sizes['720p'],
                        'wideUri': 'remote:' + body.sizes['720p'],
                        'mediaCoreId': mediaCoreId
                    };

                    // Store the thumbnail info on the content item
                    ContentDAO.Previews.storeMetadata(content, contentRevisionId.revisionId, ContentConstants.previews.DONE, thumbnailUri, null, previewMetadata, {}, function(err){
                        if (err) {
                            return callback(err);
                        }

                        // Indicate that we've just updated a preview
                        ContentAPI.emit(ContentConstants.events.UPDATED_CONTENT_PREVIEW, content);

                        return callback();
                    });
                });
            });
        });
コード例 #2
0
ファイル: test-dao.js プロジェクト: cyu019x/Hilary
                            RestAPI.Content.updateFileBody(mrvisser.restContext, contentObj.id, getStream, function(err) {
                                assert.ok(!err);

                                ContentDAO.Revisions.getAllRevisionsForContent([contentObj.id], function(err, data) {
                                    assert.ok(!err);
                                    assert.ok(data[contentObj.id]);
                                    assert.ok(data[contentObj.id].length, 5);
                                    _.each(data[contentObj.id], function(revision) {
                                        assert.equal(revision.contentId, contentObj.id);
                                        assert.equal(revision.filename, 'apereo.jpg');
                                    });
                                    return callback();
                                });
                            });
コード例 #3
0
ファイル: search.js プロジェクト: rdemarco/Hilary
var _getRevisionItems = function(contentItems, callback) {
    // Check if we need to fetch revisions.
    var revisionsToRetrieve = [];
    _.each(contentItems, function(content) {
        if (content.resourceSubType === 'collabdoc') {
            revisionsToRetrieve.push(content.latestRevisionId);
        }
    });

    if (_.isEmpty(revisionsToRetrieve)) {
        return callback(null, {});
    } else {
        ContentDAO.Revisions.getMultipleRevisions(revisionsToRetrieve, {'fields': ['revisionId', 'etherpadHtml']}, function(err, revisions) {
            if (err) {
                return callback(err);
            }

            // Map each revision by its ID.
            var revisionsById = {};
            _.each(revisions, function(revision) { revisionsById[revision.revisionId] = revision; });
            return callback(null, revisionsById);
        });
    }
};
コード例 #4
0
ファイル: api.js プロジェクト: JawadHF/Hilary
    var _onEach = function(contentRows, done) {
        log().info('Scanning %d content items to see if previews need to be reprocessed', contentRows.length);
        totalScanned += contentRows.length;

        // Get those rows we can use to filter upon
        var contentToFilter = _.filter(contentRows, function(contentRow) {
            if (contentRow.previews) {
                try {
                    contentRow.previews = JSON.parse(contentRow.previews);
                    return true;
                } catch (ex) {
                    // If the preview is invalid JSON, something bad happened. Lets try and reprocess it so the processor can better set the preview data
                    log().warn({'contentRow': contentRow}, 'Found invalid JSON for content item. Forcing regeneration of previews');
                }
            } else {
                // If there is no previews object, something is wrong. Try and reprocess it and reset it
                log().warn({'contentId': contentRow.contentId}, 'Found no previews object for content item. Forcing regeneration of previews');
            }

            // If we reach this point, it means the previews object was in an incorrect state
            // so we can't use it for filtering. We should reprocess this piece of content immediately
            totalReprocessed++;
            submitForProcessing(contentRow.contentId, contentRow.latestRevisionId);
            return false;
        });

        // 1st phase: filter based on content types
        var filteredContent = filterGenerator.filterContent(contentToFilter);

        // If we don't need to filter by revisions we can simply reprocess the latest revisions
        // of the content items that are left
        if (!filterGenerator.needsRevisions() || filteredContent.length === 0) {
            _.each(filteredContent, function(content) {
                totalReprocessed++;
                submitForProcessing(content.contentId, content.latestRevisionId);
            });
            done();
        } else {
            // We need to filter by revisions
            var contentIds = _.map(filteredContent, function(contentObj) { return contentObj.contentId; });
            ContentDAO.Revisions.getAllRevisionsForContent(contentIds, function(err, revisionsByContent) {
                if (err) {
                    log().error({'err': err}, 'Error trying to retrieve revisions for content');
                }

                // Stick the revisions on their content item
                var filteredContentById = _.indexBy(filteredContent, 'contentId');
                _.each(revisionsByContent, function(revisions, contentId) {
                    filteredContentById[contentId].revisions = revisions;
                });
                filteredContent = _.values(filteredContentById);

                // Run the second filtering phase
                filteredContent = filterGenerator.filterRevisions(filteredContent);

                // Submit all those are left
                _.each(filteredContent, function(content) {
                    _.each(content.revisions, function(revision) {
                        totalReprocessed++;
                        submitForProcessing(content.contentId, revision.revisionId);
                    });
                });

                return done();
            });
        }
    };