Skip to content

Commit

Permalink
fix: handle deploy-scoped stores on Windows (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas authored Nov 24, 2023
1 parent cd65664 commit e96286d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
27 changes: 26 additions & 1 deletion src/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import semver from 'semver'
import tmp from 'tmp-promise'
import { test, expect, beforeAll, afterEach } from 'vitest'

import { getStore } from './main.js'
import { getDeployStore, getStore } from './main.js'
import { BlobsServer } from './server.js'

beforeAll(async () => {
Expand Down Expand Up @@ -286,3 +286,28 @@ test('Lists entries', async () => {

expect(parachutesSongs2.directories).toEqual([])
})

test('Works with a deploy-scoped store', async () => {
const deployID = '655f77a1b48f470008e5879a'
const directory = await tmp.dir()
const server = new BlobsServer({
directory: directory.path,
token,
})
const { port } = await server.start()

const store = getDeployStore({
deployID,
edgeURL: `http://localhost:${port}`,
token,
siteID,
})
const key = 'my-key'

await store.set(key, 'value 1 for store 1')

expect(await store.get(key)).toBe('value 1 for store 1')

await server.stop()
await fs.rm(directory.path, { force: true, recursive: true })
})
8 changes: 6 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createReadStream, createWriteStream, promises as fs } from 'node:fs'
import http from 'node:http'
import { tmpdir } from 'node:os'
import { dirname, join, relative, resolve, sep } from 'node:path'
import { platform } from 'node:process'

import { ListResponse } from './backend/list.ts'
import { decodeMetadata, encodeMetadata, METADATA_HEADER_INTERNAL } from './metadata.ts'
Expand Down Expand Up @@ -301,12 +302,15 @@ export class BlobsServer {
return {}
}

const [, siteID, storeName, ...key] = url.pathname.split('/')
const [, siteID, rawStoreName, ...key] = url.pathname.split('/')

if (!siteID || !storeName) {
if (!siteID || !rawStoreName) {
return {}
}

// On Windows, file paths can't include the `:` character, which is used in
// deploy-scoped stores.
const storeName = platform === 'win32' ? encodeURIComponent(rawStoreName) : rawStoreName
const rootPath = resolve(this.directory, 'entries', siteID, storeName)
const dataPath = resolve(rootPath, ...key)
const metadataPath = resolve(this.directory, 'metadata', siteID, storeName, ...key)
Expand Down

0 comments on commit e96286d

Please sign in to comment.