Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-protocol/src/snapshot-url.ts
2498 views
1
/**
2
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
export interface SnapshotUrl {
8
bucketId: string;
9
fullPath: string;
10
filename: string;
11
}
12
export namespace SnapshotUrl {
13
export function parse(url: string): SnapshotUrl {
14
const parts = url.split("@");
15
if (parts.length !== 2) {
16
throw new Error(`cannot parse snapshot URL: ${url}`);
17
}
18
const [fullPath, bucketId] = parts;
19
20
const pathParts = fullPath.split("/");
21
if (pathParts.length < 1) {
22
throw new Error(`cannot parse snapshot URL: ${url}`);
23
}
24
const filename = pathParts[pathParts.length - 1];
25
return { bucketId, fullPath, filename };
26
}
27
}
28
29