A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: code refactoring
alihamuha20a683b1716
diff --git a/apps/web/src/utils/streams/export-stream.ts b/apps/web/src/utils/streams/export-stream.tsindex b95a147ad..4ac0befa4 100644--- a/apps/web/src/utils/streams/export-stream.ts+++ b/apps/web/src/utils/streams/export-stream.ts@@ -99,65 +99,56 @@ export class ExportStream extends ReadableStream<ZipFile> {const filename = sanitizeFilename(note.title, { replacement: "-" });const ext = FORMAT_TO_EXT[format];- const notebooksWithoutTopics = db.relations?.to(- { id: note.id, type: "note" },- "notebook"- );- const notebooksWithTopics = note?.notebooks;- const notebooks: Array<{ title: string; topics: Array<string> }> = [];-- notebooksWithoutTopics?.forEach((notebook) => {- notebooks.push({ title: notebook.title, topics: [] });- });-- notebooksWithTopics?.forEach((notebook: any) => {- const _topics = db.notebooks?.notebook(notebook.id).topics.all;- const topics: Array<string> = [];-- notebook?.topics?.forEach((topicId: string) => {- _topics?.forEach((topic) => {- if (topic.id === topicId) {- topics.push(topic.title);- }- });+ const notebooks = db.relations+ ?.to({ id: note.id, type: "note" }, "notebook")+ .map((notebook) => {+ return { title: notebook.title, topics: Array<string> };});+ const notebooksWithTopics: Array<{+ id: string;+ topics: Array<string>;+ }> = note?.notebooks;++ if (notebooksWithTopics)+ notebooks?.push(+ ...notebooksWithTopics.map((_notebook) => {+ const notebook = db.notebooks?.notebook(_notebook.id);+ const _topics = notebook?.topics.all;+ let topics: any;++ _notebook.topics.map((topicId: string) => {+ topics = _topics?.filter((topic) => {+ return topic.id === topicId;+ });+ });- notebooks.push({- title: db.notebooks?.notebook(notebook.id).title,- topics: topics- });- });+ return {+ title: notebook?.title,+ topics: topics?.map((topic) => topic.title)+ };+ })+ );++ const filenameWithExtension = [filename, ext].join(".").toLowerCase();+ const filePaths: Array<string> = [];- const paths: Array<string> = [];- if (notebooks?.length > 0) {+ if (notebooks && notebooks.length > 0) {notebooks.forEach((notebook) => {if (notebook.topics.length > 0)notebook.topics.forEach((topic) => {- paths.push(- makeUniqueFilename(- [filename, ext].join("."),- counters,- notebook.title,- topic- )+ filePaths.push(+ `/${notebook.title}/${topic}/${filenameWithExtension}`);});- else- paths.push(- makeUniqueFilename(- [filename, ext].join("."),- counters,- notebook.title- )- );+ else filePaths.push(`/${notebook.title}/${filenameWithExtension}`);});} else {- paths.push(makeUniqueFilename([filename, ext].join("."), counters));+ filePaths.push(filenameWithExtension);}- paths.forEach((path) => {+ filePaths.forEach((filePath) => {controller.enqueue({- path,+ path: makeUniqueFilename(filePath, counters),data: textEncoder.encode(exported),mtime: new Date(note.data.dateEdited),ctime: new Date(note.data.dateCreated)diff --git a/apps/web/src/utils/streams/utils.ts b/apps/web/src/utils/streams/utils.tsindex 110fc3b81..350915c0d 100644--- a/apps/web/src/utils/streams/utils.ts+++ b/apps/web/src/utils/streams/utils.ts@@ -19,15 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.export function makeUniqueFilename(filePath: string,- counters: Record<string, number>,- notebook?: string,- topic?: string+ counters: Record<string, number>) {- if (notebook && topic)- filePath = `/${notebook}/${topic}/${filePath.toLowerCase()}`;- else if (notebook) filePath = `/${notebook}/${filePath.toLowerCase()}`;- else filePath = filePath.toLowerCase();-counters[filePath] = (counters[filePath] || 0) + 1;if (counters[filePath] === 1) return filePath;