Skip to content

Commit

Permalink
fix s3 get object url when custom s3 domain (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
lihsai0 authored May 8, 2024
1 parent 41b855f commit 452e18d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
14 changes: 12 additions & 2 deletions kodo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ export class Kodo implements Adapter {
if (bucketResponse.data.perm && bucketResponse.data.perm > 0) {
const defautDomainData = defaultDomainQuery.data;
const domains: Domain[] = [];
if (defautDomainData.domain && defautDomainData.protocol) {
if (
defautDomainData.domain &&
defautDomainData.protocol &&
defautDomainData.isAvailable
) {
domains.push({
name: defautDomainData.domain,
protocol: defautDomainData.protocol,
Expand All @@ -319,12 +323,18 @@ export class Kodo implements Adapter {
}
const result: Domain[] = [];
domainResponse.data.forEach((domain: any) => {
if (
domain.domain === defaultDomainQuery.data.domain &&
!defaultDomainQuery.data.isAvailable
) {
return
}
const resultItem: Domain = {
name: domain.domain,
protocol: domainShouldHttps[domain.domain] ? 'https' : 'http',
type: 'others',
apiScope: domain.api_scope === 0 ? 'kodo' : 's3',
private: bucketResponse.data.private != 0,
private: bucketResponse.data.private != 0 || domain.api_scope === 1,
protected: bucketResponse.data.protected != 0,
};
if (!domain.domain_types?.length) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kodo-s3-adapter-sdk",
"version": "0.5.0",
"version": "0.5.1",
"description": "Adapter for Kodo & S3 API",
"main": "dist/index.js",
"repository": "github.com/bachue/kodo-s3-adapter-sdk",
Expand Down
18 changes: 16 additions & 2 deletions s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,23 @@ export class S3 extends Kodo {
);
}

async getObjectURL(s3RegionId: string, object: StorageObject, _domain?: Domain, deadline?: Date): Promise<URL> {
async getObjectURL(s3RegionId: string, object: StorageObject, domain?: Domain, deadline?: Date): Promise<URL> {
// if domain is not undefined, use the domain, else use the default s3 endpoint
const s3Promise: Promise<AWS.S3> = domain
? Promise.resolve(new AWS.S3({
apiVersion: '2006-03-01',
region: s3RegionId,
endpoint: `${domain.protocol}://${domain.name}`,
credentials: {
accessKeyId: this.adapterOption.accessKey,
secretAccessKey: this.adapterOption.secretKey,
},
signatureVersion: 'v4',
s3BucketEndpoint: true,
}))
: this.getClient(s3RegionId);
const [s3, bucketId] = await Promise.all([
this.getClient(s3RegionId),
s3Promise,
this.fromKodoBucketNameToS3BucketId(object.bucket),
]);
const expires = deadline
Expand Down

0 comments on commit 452e18d

Please sign in to comment.