fix(logs): extra CRs in downloading container logs EE-1973 (#6041)

pull/6120/head
Hao Zhang 2021-11-19 12:21:16 +08:00 committed by GitHub
parent 33871eb447
commit b596d0febd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 2 deletions

View File

@ -32,3 +32,5 @@ angular
export const PORTAINER_FADEOUT = 1500;
export const STACK_NAME_VALIDATION_REGEX = '^[-_a-z0-9]+$';
export const TEMPLATE_NAME_VALIDATION_REGEX = '^[-_a-z0-9]+$';
export const BROWSER_OS_PLATFORM = navigator.userAgent.indexOf('Windows NT') > -1 ? 'win' : 'lin';
export const NEW_LINE_BREAKER = BROWSER_OS_PLATFORM === 'win' ? '\r\n' : '\n';

View File

@ -1,5 +1,6 @@
import moment from 'moment';
import _ from 'lodash-es';
import { NEW_LINE_BREAKER } from '@/constants';
angular.module('portainer.docker').controller('LogViewerController', [
'clipboard',
@ -48,7 +49,8 @@ angular.module('portainer.docker').controller('LogViewerController', [
};
this.downloadLogs = function () {
const data = new Blob([_.reduce(this.state.filteredLogs, (acc, log) => acc + '\n' + log.line, '')]);
// To make the feature of downloading container logs working both on Windows and Linux, we need to use correct new line breakers on corresponding OS.
const data = new Blob([_.reduce(this.state.filteredLogs, (acc, log) => acc + log.line + NEW_LINE_BREAKER, '')]);
FileSaver.saveAs(data, this.resourceName + '_logs.txt');
};
},

View File

@ -46,7 +46,7 @@ angular.module('portainer.docker').factory('LogHelper', [
function stripHeaders(logs) {
logs = logs.substring(8);
logs = logs.replace(/\n(.{8})/g, '\n\r');
logs = logs.replace(/\r?\n(.{8})/g, '\n');
return logs;
}