this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Save page count to db

modamo-gh 6c157162 d23695ac

+171 -7
+3 -2
app/book/[bookID]/page.tsx
··· 31 31 32 32 numberOfPages = await fetchNumberOfPages( 33 33 book.value.authors, 34 + book.value.hiveId, 34 35 book.value.title 35 36 ); 36 37 } catch (error) { ··· 42 43 <Header /> 43 44 <div className="gap-4 grid grid-cols-2 row-span-9"> 44 45 <div className="bg-emerald-900 col-span-1 gap-4 grid grid-rows-3 p-4 rounded-2xl"> 45 - <div className="bg-amber-100 flex items-center justify-center rounded-2xl row-span-2"> 46 - <div className="aspect-2/3 h-full overflow-hidden relative rounded-2xl"> 46 + <div className="bg-amber-100 flex items-center justify-center p-4 rounded-2xl row-span-2"> 47 + <div className="aspect-2/3 border-4 border-emerald-900 h-full overflow-hidden relative rounded-2xl"> 47 48 <Image 48 49 alt={`Book cover for ${book.value.title} by ${book.value.authors}`} 49 50 className="object-cover"
+35 -3
lib/books/google.ts
··· 1 - export const fetchNumberOfPages = async (authors: string, title: string) => { 1 + import { supabase } from "../supabase/server"; 2 + 3 + export const fetchNumberOfPages = async ( 4 + authors: string, 5 + hiveID: string, 6 + title: string 7 + ) => { 8 + const { data: existing} = await supabase 9 + .from("books") 10 + .select("page_count") 11 + .eq("hive_id", hiveID); 12 + 13 + if (existing?.page_count) { 14 + return existing.page_count; 15 + } else { 16 + console.log("Nada"); 17 + } 18 + 2 19 try { 3 20 const response = await fetch( 4 21 `https://www.googleapis.com/books/v1/volumes?q=intitle:${encodeURIComponent( 5 22 title 6 - )}+inauthor:${encodeURIComponent(authors)}&maxResults=1` 23 + )}+inauthor:${encodeURIComponent(authors)}&key=${ 24 + process.env.GOOGLE_BOOKS_API_KEY 25 + }&maxResults=1` 7 26 ); 8 27 const json = await response.json(); 9 - const volumeInfo = json.items[0].volumeInfo; 28 + const volumeInfo = json.items?.[0].volumeInfo; 29 + 30 + const {data, error: e} = await supabase.from("books").upsert({ 31 + authors, 32 + hive_id: hiveID, 33 + page_count: Number(volumeInfo.pageCount), 34 + title 35 + }, {onConflict: "hive_id"}); 36 + 37 + if (e) { 38 + console.error("Supabase upsert error:", e); 39 + } else { 40 + console.log("Inserted"); 41 + } 10 42 11 43 return Number(volumeInfo.pageCount); 12 44 } catch (error) {
+6
lib/supabase/server.ts
··· 1 + import { createClient } from "@supabase/supabase-js"; 2 + 3 + export const supabase = createClient( 4 + process.env.SUPABASE_URL, 5 + process.env.SUPABASE_SERVICE_ROLE_KEY 6 + );
+126 -2
package-lock.json
··· 10 10 "dependencies": { 11 11 "@atproto/api": "^0.18.20", 12 12 "@atproto/oauth-client-node": "^0.3.16", 13 + "@supabase/supabase-js": "^2.95.1", 13 14 "better-sqlite3": "^12.6.2", 14 15 "kysely": "^0.28.11", 15 16 "next": "16.1.6", ··· 1613 1614 "dev": true, 1614 1615 "license": "MIT" 1615 1616 }, 1617 + "node_modules/@supabase/auth-js": { 1618 + "version": "2.95.1", 1619 + "resolved": "https://registry.npmjs.org/@supabase/auth-js/-/auth-js-2.95.1.tgz", 1620 + "integrity": "sha512-fl1MeO3GgRXX0fQZ1/ty2bIlEWGzHsC1dwtrmxr0OkjRf0QjkHQ+SMjby4iqN9WnASHb8AH4sP6FjG3bJVo3fg==", 1621 + "license": "MIT", 1622 + "dependencies": { 1623 + "tslib": "2.8.1" 1624 + }, 1625 + "engines": { 1626 + "node": ">=20.0.0" 1627 + } 1628 + }, 1629 + "node_modules/@supabase/functions-js": { 1630 + "version": "2.95.1", 1631 + "resolved": "https://registry.npmjs.org/@supabase/functions-js/-/functions-js-2.95.1.tgz", 1632 + "integrity": "sha512-JiF16+aCkh0Kqyc3xXGh6cUEuTKIFPix3dZNl/SjCb5vaWuMSeQaROwPnQ89BeTH1Z7VS43ydPUzD0zcaxULGA==", 1633 + "license": "MIT", 1634 + "dependencies": { 1635 + "tslib": "2.8.1" 1636 + }, 1637 + "engines": { 1638 + "node": ">=20.0.0" 1639 + } 1640 + }, 1641 + "node_modules/@supabase/postgrest-js": { 1642 + "version": "2.95.1", 1643 + "resolved": "https://registry.npmjs.org/@supabase/postgrest-js/-/postgrest-js-2.95.1.tgz", 1644 + "integrity": "sha512-1g97xV0jmEA5wmRGpJfbuO0F3bNJn+JERkRu0/YiUeodg7GKT4o06+LoayFDwrquXK+kzrxnDUZAkSOPELbGsg==", 1645 + "license": "MIT", 1646 + "dependencies": { 1647 + "tslib": "2.8.1" 1648 + }, 1649 + "engines": { 1650 + "node": ">=20.0.0" 1651 + } 1652 + }, 1653 + "node_modules/@supabase/realtime-js": { 1654 + "version": "2.95.1", 1655 + "resolved": "https://registry.npmjs.org/@supabase/realtime-js/-/realtime-js-2.95.1.tgz", 1656 + "integrity": "sha512-ZBzxkAqPq8D4vfoAG2D6H1lZuaOE2PpUVZs0tGIeKpgRYMsfG2wn/njKKNQdXEuu0ngXva/QI98GsZF8Pbqyhg==", 1657 + "license": "MIT", 1658 + "dependencies": { 1659 + "@types/phoenix": "^1.6.6", 1660 + "@types/ws": "^8.18.1", 1661 + "tslib": "2.8.1", 1662 + "ws": "^8.18.2" 1663 + }, 1664 + "engines": { 1665 + "node": ">=20.0.0" 1666 + } 1667 + }, 1668 + "node_modules/@supabase/storage-js": { 1669 + "version": "2.95.1", 1670 + "resolved": "https://registry.npmjs.org/@supabase/storage-js/-/storage-js-2.95.1.tgz", 1671 + "integrity": "sha512-OB2TvLx5hXJ9MWd3LFze9+kAB2Ap/EWSwLeEdxQZrV+JhGtUxuS2wxHnVMEhNiu/k3gyRNAdI9888RRmC2wnLA==", 1672 + "license": "MIT", 1673 + "dependencies": { 1674 + "iceberg-js": "^0.8.1", 1675 + "tslib": "2.8.1" 1676 + }, 1677 + "engines": { 1678 + "node": ">=20.0.0" 1679 + } 1680 + }, 1681 + "node_modules/@supabase/supabase-js": { 1682 + "version": "2.95.1", 1683 + "resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.95.1.tgz", 1684 + "integrity": "sha512-ow3ZqJfb3JkLF8MDxVOl3FAy39pGF1uWgr5nitcwEMwjJTt7yk/s8sQPcGrTL29xOqQB+v5hQDWYr7906k4a3A==", 1685 + "license": "MIT", 1686 + "dependencies": { 1687 + "@supabase/auth-js": "2.95.1", 1688 + "@supabase/functions-js": "2.95.1", 1689 + "@supabase/postgrest-js": "2.95.1", 1690 + "@supabase/realtime-js": "2.95.1", 1691 + "@supabase/storage-js": "2.95.1" 1692 + }, 1693 + "engines": { 1694 + "node": ">=20.0.0" 1695 + } 1696 + }, 1616 1697 "node_modules/@swc/helpers": { 1617 1698 "version": "0.5.15", 1618 1699 "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.15.tgz", ··· 1939 2020 "version": "20.19.30", 1940 2021 "resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.30.tgz", 1941 2022 "integrity": "sha512-WJtwWJu7UdlvzEAUm484QNg5eAoq5QR08KDNx7g45Usrs2NtOPiX8ugDqmKdXkyL03rBqU5dYNYVQetEpBHq2g==", 1942 - "dev": true, 1943 2023 "license": "MIT", 1944 2024 "dependencies": { 1945 2025 "undici-types": "~6.21.0" 1946 2026 } 2027 + }, 2028 + "node_modules/@types/phoenix": { 2029 + "version": "1.6.7", 2030 + "resolved": "https://registry.npmjs.org/@types/phoenix/-/phoenix-1.6.7.tgz", 2031 + "integrity": "sha512-oN9ive//QSBkf19rfDv45M7eZPi0eEXylht2OLEXicu5b4KoQ1OzXIw+xDSGWxSxe1JmepRR/ZH283vsu518/Q==", 2032 + "license": "MIT" 1947 2033 }, 1948 2034 "node_modules/@types/react": { 1949 2035 "version": "19.2.10", ··· 1965 2051 "@types/react": "^19.2.0" 1966 2052 } 1967 2053 }, 2054 + "node_modules/@types/ws": { 2055 + "version": "8.18.1", 2056 + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz", 2057 + "integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==", 2058 + "license": "MIT", 2059 + "dependencies": { 2060 + "@types/node": "*" 2061 + } 2062 + }, 1968 2063 "node_modules/@typescript-eslint/eslint-plugin": { 1969 2064 "version": "8.54.0", 1970 2065 "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.54.0.tgz", ··· 4438 4533 "license": "MIT", 4439 4534 "dependencies": { 4440 4535 "hermes-estree": "0.25.1" 4536 + } 4537 + }, 4538 + "node_modules/iceberg-js": { 4539 + "version": "0.8.1", 4540 + "resolved": "https://registry.npmjs.org/iceberg-js/-/iceberg-js-0.8.1.tgz", 4541 + "integrity": "sha512-1dhVQZXhcHje7798IVM+xoo/1ZdVfzOMIc8/rgVSijRK38EDqOJoGula9N/8ZI5RD8QTxNQtK/Gozpr+qUqRRA==", 4542 + "license": "MIT", 4543 + "engines": { 4544 + "node": ">=20.0.0" 4441 4545 } 4442 4546 }, 4443 4547 "node_modules/ieee754": { ··· 7189 7293 "version": "6.21.0", 7190 7294 "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", 7191 7295 "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", 7192 - "dev": true, 7193 7296 "license": "MIT" 7194 7297 }, 7195 7298 "node_modules/unicode-segmenter": { ··· 7400 7503 "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", 7401 7504 "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", 7402 7505 "license": "ISC" 7506 + }, 7507 + "node_modules/ws": { 7508 + "version": "8.19.0", 7509 + "resolved": "https://registry.npmjs.org/ws/-/ws-8.19.0.tgz", 7510 + "integrity": "sha512-blAT2mjOEIi0ZzruJfIhb3nps74PRWTCz1IjglWEEpQl5XS/UNama6u2/rjFkDDouqr4L67ry+1aGIALViWjDg==", 7511 + "license": "MIT", 7512 + "engines": { 7513 + "node": ">=10.0.0" 7514 + }, 7515 + "peerDependencies": { 7516 + "bufferutil": "^4.0.1", 7517 + "utf-8-validate": ">=5.0.2" 7518 + }, 7519 + "peerDependenciesMeta": { 7520 + "bufferutil": { 7521 + "optional": true 7522 + }, 7523 + "utf-8-validate": { 7524 + "optional": true 7525 + } 7526 + } 7403 7527 }, 7404 7528 "node_modules/yallist": { 7405 7529 "version": "3.1.1",
+1
package.json
··· 11 11 "dependencies": { 12 12 "@atproto/api": "^0.18.20", 13 13 "@atproto/oauth-client-node": "^0.3.16", 14 + "@supabase/supabase-js": "^2.95.1", 14 15 "better-sqlite3": "^12.6.2", 15 16 "kysely": "^0.28.11", 16 17 "next": "16.1.6",