文件操作 - progress.js
返回文件管理
返回主菜单
删除本文件
文件: /home/www/public/wp-content/plugins/ionos-journey/js/journey/helpers/progress.js
编辑文件内容
import UrlHelper from './url-helper.js'; export default class Progress { static versionConstraint = '1'; static timestamp = -1; static progressKey = 'ionos-journey-progress-'; static currentProgress = []; static init( progressString, userId ) { this.userId = userId; if ( localStorage.getItem( Progress.progressKey + this.userId ) === null ) { this.version = this.versionConstraint; return; } if ( localStorage.getItem( Progress.progressKey + userId ).length > 0 ) { const progressData = JSON.parse( localStorage.getItem( Progress.progressKey + this.userId ) ); this.version = progressData.version; this.timestamp = progressData.timestamp; this.currentProgress = progressData.data; } if ( progressString.length > 0 ) { const progressData = JSON.parse( progressString ); if ( progressData.timestamp > this.timestamp ) { this.version = progressData.version; this.timestamp = progressData.timestamp; this.currentProgress = progressData.data; } else if ( progressData.timestamp < this.timestamp ) { this.persistProgress( localStorage.getItem( Progress.progressKey + this.userId ) ); } } else if ( localStorage.getItem( Progress.progressKey + userId ).length > 0 ) { this.persistProgress( localStorage.getItem( Progress.progressKey + this.userId ) ); } } static store( progress ) { if ( Date.now() > this.timestamp ) { const progressData = {}; progressData.version = this.versionConstraint; progressData.timestamp = Date.now(); progressData.data = progress; localStorage.setItem( Progress.progressKey + this.userId, JSON.stringify( progressData ) ); this.persistProgress( JSON.stringify( progressData ) ); } } static get() { return this.currentProgress; } static clear() { localStorage.removeItem( Progress.progressKey + this.userId ); } static clearMeta( retry = false ) { const httpRequest = new XMLHttpRequest(); httpRequest.onreadystatechange = function () { if ( this.readyState === 4 && this.status !== 200 && retry ) { Progress.clear( ! retry ); } }; let url = UrlHelper.getUrl().toString(); if ( url.includes( '?' ) ) { url = url.split( '?' )[ 0 ]; } httpRequest.open( 'POST', url + '?journey_persistance=clear' ); httpRequest.send(); } static persistProgress( progress, retry = true ) { const httpRequest = new XMLHttpRequest(); httpRequest.onreadystatechange = function () { if ( this.readyState === 4 && this.status !== 200 && retry ) { Progress.persistProgress( progress, ! retry ); } }; let url = UrlHelper.getUrl().toString(); if ( url.includes( '?' ) ) { url = url.split( '?' )[ 0 ]; } httpRequest.open( 'POST', url + '?journey_persistance=save' ); httpRequest.setRequestHeader( 'Content-type', 'application/json' ); httpRequest.send( progress ); } }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件