more debug, why!
This commit is contained in:
parent
4daf54106b
commit
74c85d6ec4
|
@ -11,8 +11,8 @@
|
|||
"function": "/publishDictionary"
|
||||
},
|
||||
{
|
||||
"source": "/willError",
|
||||
"function": "/willError"
|
||||
"source": "/testAuth",
|
||||
"function": "/testAuth"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
const nano = require("nano");
|
||||
const oldCouch = nano(process.env.OLD_WORDLIST_COUCHDB);
|
||||
const newCouch = nano(process.env.LINGDOCS_COUCHDB);
|
||||
const email = process.argv[2];
|
||||
const newEmail = process.argv[3];
|
||||
|
||||
function stringToHex(str) {
|
||||
const arr1 = [];
|
||||
for (let n = 0, l = str.length; n < l; n ++) {
|
||||
const hex = Number(str.charCodeAt(n)).toString(16);
|
||||
arr1.push(hex);
|
||||
}
|
||||
return arr1.join('');
|
||||
}
|
||||
|
||||
async function getOldWordList() {
|
||||
const usersDb = oldCouch.use("_users");
|
||||
const res = await usersDb.find({
|
||||
selector: {
|
||||
originalEmail: email,
|
||||
},
|
||||
});
|
||||
const { name } = res.docs[0];
|
||||
const tag = stringToHex(name);
|
||||
const userDb = oldCouch.db.use(`userdb-${tag}`);
|
||||
const { rows } = await userDb.list({ include_docs: true });
|
||||
const allDocs = rows.map((row) => row.doc);
|
||||
return allDocs
|
||||
}
|
||||
|
||||
function convertWordList(list) {
|
||||
const now = Date.now();
|
||||
return list.map((item) => ({
|
||||
_id: item._id,
|
||||
warmup: "done",
|
||||
supermemo: {
|
||||
interval: 0,
|
||||
repetition: 0,
|
||||
efactor: 2.5
|
||||
},
|
||||
dueDate: now,
|
||||
entry: { ...item.w },
|
||||
notes: item.notes,
|
||||
}));
|
||||
}
|
||||
|
||||
async function uploadToNewDb(wordlist) {
|
||||
const usersDb = newCouch.use("_users");
|
||||
const res = await usersDb.find({
|
||||
selector: {
|
||||
email: newEmail || email,
|
||||
},
|
||||
});
|
||||
const { name } = res.docs[0];
|
||||
const tag = stringToHex(name);
|
||||
const userDb = newCouch.db.use(`userdb-${tag}`);
|
||||
await userDb.bulk({ docs: wordlist });
|
||||
}
|
||||
|
||||
// async function updateWarmup() {
|
||||
// const usersDb = newCouch.use("_users");
|
||||
// const res = await usersDb.find({
|
||||
// selector: {
|
||||
// email: newEmail || email,
|
||||
// },
|
||||
// });
|
||||
// const { name } = res.docs[0];
|
||||
// const tag = stringToHex(name);
|
||||
// const userDb = newCouch.db.use(`userdb-${tag}`);
|
||||
// const { rows } = await userDb.list({ include_docs: true });
|
||||
// const allDocs = rows.map((row) => row.doc);
|
||||
// const updated = allDocs.map((d) => ({ ...d, warmup: "done" }));
|
||||
// await userDb.bulk({ docs: updated });
|
||||
// }
|
||||
|
||||
async function main() {
|
||||
const oldWordList = await getOldWordList();
|
||||
const newWordList = convertWordList(oldWordList);
|
||||
uploadToNewDb(newWordList)
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
|
|
@ -4,18 +4,24 @@ import auth from "./middleware/lingdocs-auth";
|
|||
import publish from "./publish";
|
||||
|
||||
export const publishDictionary = functions.https.onRequest(
|
||||
auth((req, res: functions.Response<FT.PublishDictionaryResponse | FT.FunctionError>) => {
|
||||
auth(async (req, res: functions.Response<FT.PublishDictionaryResponse | FT.FunctionError>) => {
|
||||
if (req.user.level !== "editor") {
|
||||
res.status(403).send({ ok: false, error: "403 forbidden" });
|
||||
return;
|
||||
}
|
||||
publish().then(res.send);
|
||||
try {
|
||||
res.send(await publish());
|
||||
} catch (e) {
|
||||
const error: string = ("message" in e && typeof e.message === "string") ? e.message : "server error";
|
||||
res.status(500).send({ ok: false, error });
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
export const willError = functions.https.onRequest((req, res) => {
|
||||
auth((req, res: functions.Response<FT.PublishDictionaryResponse | FT.FunctionError>) => {
|
||||
throw new Error("this is an error");
|
||||
export const testAuth = functions.https.onRequest((req, res) => {
|
||||
auth(async (req, res) => {
|
||||
// @ts-ignore
|
||||
res.send({ ok: true, user: req.user })
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -30,9 +30,9 @@ const Account = ({ user, loadUser }: { user: AT.LingdocsUser | undefined, loadUs
|
|||
setUpgradeError("");
|
||||
setWaiting(false);
|
||||
window.addEventListener("message", handleIncomingMessage);
|
||||
console.log("send test erroring func");
|
||||
fetch("https://functions.lingdocs.com/willError", { credentials: "include" }).then((res) => res.text()).then((res) => {
|
||||
console.log("test error here");
|
||||
console.log("send test auth func");
|
||||
fetch("https://functions.lingdocs.com/testAuth", { credentials: "include" }).then((res) => res.text()).then((res) => {
|
||||
console.log("test auth here");
|
||||
console.log(res);
|
||||
});
|
||||
return () => {
|
||||
|
|
Loading…
Reference in New Issue