/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
const fs = require('fs');
const path = require('path');
const util = require('util');
const { RESULT_FILE_NAME } = require('./store');
const readFileAsync = util.promisify(fs.readFile);
function resolveImagePath(imageUrl) {
if (!imageUrl) {
return '';
}
// The original image path is relative to the client.
return imageUrl.replace(/\\/g, '/').replace(/\.\.\/tmp/g, './tmp');
}
async function inlineImage(imageUrl) {
if (!imageUrl) {
return '';
}
try {
let fullPath = path.join(__dirname, resolveImagePath(imageUrl));
// let img = await jimp.read(fullPath);
// img.quality(70);
// return img.getBase64Async('image/jpeg');
let imgBuffer = await readFileAsync(fullPath);
return 'data:image/webp;base64,' + imgBuffer.toString('base64');
}
catch (e) {
console.error(e);
return '';
}
}
function shouldShowMarkAsExpected(test, expectedSource, expectedVersion) {
if (expectedSource === 'release' && (expectedVersion !== test.expectedVersion)
|| !test.markedAsExpected
) {
return false;
}
if (expectedSource !== 'release' && test.markedAsExpected.length > 0) {
return true;
}
for (let i = 0; i < test.markedAsExpected.length; i++) {
if (test.markedAsExpected[i].lastVersion === expectedVersion) {
return true;
}
}
return false;
}
function generateMarkDetails(test) {
if (!test.markedAsExpected || test.markedAsExpected.length === 0) {
return '';
}
let markDetailsHtml = `