mirror of
https://github.com/yang991178/fluent-reader.git
synced 2025-03-03 19:08:36 +01:00
sequential source insertion
This commit is contained in:
parent
fe0a8b9f17
commit
48ebd8681a
@ -116,6 +116,7 @@
|
|||||||
"errorParse": "An error has occurred when parsing the OPML file.",
|
"errorParse": "An error has occurred when parsing the OPML file.",
|
||||||
"errorParseHint": "Please ensure that the file isn't corrupted and is encoded with UTF-8.",
|
"errorParseHint": "Please ensure that the file isn't corrupted and is encoded with UTF-8.",
|
||||||
"errorImport": "Error importing {count, plural, =1 {# source} other {# sources}}.",
|
"errorImport": "Error importing {count, plural, =1 {# source} other {# sources}}.",
|
||||||
|
"exist": "This source already exists.",
|
||||||
"opmlFile": "OPML File",
|
"opmlFile": "OPML File",
|
||||||
"name": "Source name",
|
"name": "Source name",
|
||||||
"editName": "Edit name",
|
"editName": "Edit name",
|
||||||
|
@ -114,6 +114,7 @@
|
|||||||
"errorParse": "解析OPML文件时出错",
|
"errorParse": "解析OPML文件时出错",
|
||||||
"errorParseHint": "请确保OPML文件完整且使用UTF-8编码。",
|
"errorParseHint": "请确保OPML文件完整且使用UTF-8编码。",
|
||||||
"errorImport": "导入{count}项订阅源时出错",
|
"errorImport": "导入{count}项订阅源时出错",
|
||||||
|
"exist": "该订阅源已存在",
|
||||||
"opmlFile": "OPML文件",
|
"opmlFile": "OPML文件",
|
||||||
"name": "订阅源名称",
|
"name": "订阅源名称",
|
||||||
"editName": "修改名称",
|
"editName": "修改名称",
|
||||||
|
@ -204,29 +204,26 @@ export function addSourceFailure(err, batch: boolean): SourceActionTypes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertSource(source: RSSSource, trials = 0): AppThunk<Promise<RSSSource>> {
|
let insertPromises = Promise.resolve()
|
||||||
return (dispatch, getState) => {
|
function insertSource(source: RSSSource): AppThunk<Promise<RSSSource>> {
|
||||||
|
return (_, getState) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (trials >= 25) {
|
insertPromises = insertPromises.then(() => new Promise(innerResolve => {
|
||||||
reject("Failed to insert the source into NeDB.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let sids = Object.values(getState().sources).map(s => s.sid)
|
let sids = Object.values(getState().sources).map(s => s.sid)
|
||||||
source.sid = Math.max(...sids, -1) + 1
|
source.sid = Math.max(...sids, -1) + 1
|
||||||
db.sdb.insert(source, (err, inserted) => {
|
db.sdb.insert(source, (err, inserted) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (/^Can't insert key [0-9]+,/.test(err.message)) {
|
if ((new RegExp(`^Can't insert key ${source.url},`)).test(err.message)) {
|
||||||
console.log("sid conflict")
|
reject(intl.get("sources.exist"))
|
||||||
dispatch(insertSource(source, trials + 1))
|
|
||||||
.then(inserted => resolve(inserted))
|
|
||||||
.catch(err => reject(err))
|
|
||||||
} else {
|
} else {
|
||||||
reject(err)
|
reject(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resolve(inserted)
|
resolve(inserted)
|
||||||
}
|
}
|
||||||
|
innerResolve()
|
||||||
})
|
})
|
||||||
|
}))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ export async function parseRSS(url: string) {
|
|||||||
throw new Error(intl.get("log.parseError"))
|
throw new Error(intl.get("log.parseError"))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(result.statusText)
|
throw new Error(result.status + " " + result.statusText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user