Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm unable to publish #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/routes/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ export async function getPackagePackument (c) {
return c.json(ret, 200)
}

async function mergeTags(db, pkg, tags) {
const selectQuery = `SELECT name, tags FROM packages WHERE name="${pkg}"`
const rows = await db.prepare(selectQuery).run()
if (rows.results.length) {
tags = { ...JSON.parse(rows.results[0].tags), ...tags }
}
const insertQueryFn = (tags) => {
const strTags = `json('${JSON.stringify(tags)}')`
return `INSERT INTO packages (name, tags) VALUES ("${pkg}", ${strTags})
ON CONFLICT(name) DO UPDATE SET tags=${strTags}`
}
await db.prepare(insertQueryFn(tags)).run()
}

export async function publishPackage (c) {
const { pkg } = packageSpec(c)
const body = await c.req.json()
Expand All @@ -135,8 +149,7 @@ export async function publishPackage (c) {
const new_versions = Object.keys(body.versions).filter(v => !versions.includes(v))

if (!results || results.length === 0) {
const insertQuery = `INSERT INTO packages (name, tags) VALUES ("${pkg}", json('{"latest": "${new_versions[0]}"}'))`
await c.env.DB.prepare(insertQuery).run()
await mergeTags(c.env.DB, pkg, { latest: new_versions[0] })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this, somewhat, expands our tagging support, we should validate the tag values before inserting/updating.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how could this been done.

}

// check for conflicts in publishing vs. existing
Expand Down
4 changes: 4 additions & 0 deletions src/utils/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import getNpmTarballUrl from 'get-npm-tarball-url'
import semver from 'semver'

export async function extractPackageJSON (buffer) {
console.log(`ext-1`, buffer);
const blob = new Blob([Buffer.from(buffer)])
console.log(`ext-2`);
const stream = blob.stream().pipeThrough(new DecompressionStream('gzip'))
console.log(`ext-3`);
for await (const obj of extract(stream)) {
console.log(`ext-3.1`, obj.header.name);
Comment on lines +8 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove logs meant for debugging

if (obj.header.name === 'package/package.json') {
return JSON.parse(await obj.text())
}
Expand Down