Fix: rewrite filterUsercss
This commit is contained in:
parent
33200dbde4
commit
a395df18f9
|
@ -372,8 +372,15 @@ function filterStylesInternal({
|
||||||
// Parse the source and find the duplication
|
// Parse the source and find the duplication
|
||||||
// {id: int, style: object, source: string, checkDup: boolean}
|
// {id: int, style: object, source: string, checkDup: boolean}
|
||||||
function filterUsercss(req) {
|
function filterUsercss(req) {
|
||||||
return Promise.resolve().then(() => {
|
|
||||||
let style;
|
let style;
|
||||||
|
let pendingBuild;
|
||||||
|
return buildMeta()
|
||||||
|
.then(buildSection)
|
||||||
|
.then(decide)
|
||||||
|
.catch(err => ({status: 'error', error: err.message}));
|
||||||
|
|
||||||
|
function buildMeta() {
|
||||||
|
return new Promise(resolve => {
|
||||||
if (req.source) {
|
if (req.source) {
|
||||||
style = usercss.buildMeta(req.source);
|
style = usercss.buildMeta(req.source);
|
||||||
} else {
|
} else {
|
||||||
|
@ -382,18 +389,26 @@ function filterUsercss(req) {
|
||||||
if (!style.id && req.id) {
|
if (!style.id && req.id) {
|
||||||
style.id = req.id;
|
style.id = req.id;
|
||||||
}
|
}
|
||||||
let pending;
|
resolve();
|
||||||
if (!style.sections || !style.sections.length) {
|
});
|
||||||
pending = usercss.buildCode(style);
|
|
||||||
} else {
|
|
||||||
pending = Promise.resolve(style);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildSection() {
|
||||||
|
if (!style.sections || !style.sections.length) {
|
||||||
|
pendingBuild = usercss.buildCode(style);
|
||||||
|
} else {
|
||||||
|
pendingBuild = Promise.resolve(style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function decide() {
|
||||||
|
// decide result
|
||||||
if (!style.id && req.checkDup) {
|
if (!style.id && req.checkDup) {
|
||||||
return Promise.all([pending, findDupUsercss(style)])
|
return Promise.all([pendingBuild, findDupUsercss(style)])
|
||||||
.then(([, dup]) => ({status: 'success', style, dup}));
|
.then(([, dup]) => ({status: 'success', style, dup}));
|
||||||
}
|
}
|
||||||
return pending.then(() => ({status: 'success', style}));
|
return pendingBuild.then(() => ({status: 'success', style}));
|
||||||
}).catch(err => ({status: 'error', error: String(err)}));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveUsercss(style) {
|
function saveUsercss(style) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user