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