Skip to content

Commit

Permalink
feat(zotero): add version to url query
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenlx committed Oct 23, 2022
1 parent 72f94cd commit 4a56cab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/zotero/content/zotero-obsidian-note.ts
Expand Up @@ -2,6 +2,7 @@ import type { AnnotationsQuery, ItemQuery, ItemsQuery } from "@obzt/common";
import { stringifyQuery } from "@obzt/common";
import assertNever from "assert-never";
import { uniqBy } from "lodash-es";
import version from "../gen/version.js";

// import { debug } from "./debug";
import patchReaderInstance from "./patch-annot";
Expand Down Expand Up @@ -114,11 +115,13 @@ class ObsidianNote {
type === "annotation" ? items[0].parentItem?.parentItem : items[0];
if (type === "item") {
query = {
version,
type,
items: items.map(buildItemRecord),
};
} else if (type === "annotation") {
query = {
version,
type,
annots: items.map(buildItemRecord),
parent: buildItemRecord(infoItem),
Expand Down
6 changes: 6 additions & 0 deletions lib/common/src/qs.ts
Expand Up @@ -20,12 +20,14 @@ export const stringifyQuery = (
) => {
if (obj.type === "item") {
const query = {
version: obj.version,
type: obj.type,
items: obj.items.map((i) => JSON.stringify(i)),
};
return stringifyUrl({ url, query }, stringifyOptions);
} else if (obj.type === "annotation") {
const query = {
version: obj.version,
type: obj.type,
annots: obj.annots.map((i) => JSON.stringify(i)),
parent: JSON.stringify(obj.parent),
Expand Down Expand Up @@ -53,11 +55,13 @@ export const parseQuery = (
): AnnotationsQuery | ItemsQuery => {
if (query.type === "item") {
return {
version: query.version,
type: query.type,
items: toItems(query, "items"),
};
} else if (query.type === "annotation") {
return {
version: query.version,
type: query.type,
annots: toItems(query, "annots"),
parent: JSON.parse(query.parent),
Expand All @@ -74,12 +78,14 @@ export interface ItemQuery {
groupID?: number;
}
export interface AnnotationsQuery {
version: string;
type: "annotation";
annots: ItemQuery[];
parent: ItemQuery;
}

export interface ItemsQuery {
version: string;
type: "item";
items: ItemQuery[];
}

0 comments on commit 4a56cab

Please sign in to comment.