Skip to content

Commit 85a2d9a

Browse files
authored
Merge pull request #23 from chunksnbits/fix/dot-chars-public-id
fix: remove format extension for public-id
2 parents e387c26 + f41d461 commit 85a2d9a

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

packages/url/__tests__/url.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('Url', () => {
8080
forceVersion: true,
8181
})).toEqual('')
8282
});
83-
83+
8484
it('should not force a version when it already contains a version ', () => {
8585
expect(getVersion('v3/a', {
8686
forceVersion: true,
@@ -97,10 +97,6 @@ describe('Url', () => {
9797
expect(getPathToAsset('example', {})).toBe('example')
9898
})
9999

100-
it('should return publicid path with new extension', () => {
101-
expect(getPathToAsset('example.gif', { format: '.jpg' })).toBe('example.jpg')
102-
})
103-
104100
it('should return publicId with suffix', () => {
105101
expect(getPathToAsset('example', { urlSuffix: 'hello' })).toBe('example/hello')
106102
})
@@ -130,7 +126,7 @@ describe('Url', () => {
130126
expect(url('example', {
131127
cloudName: 'demo',
132128
forceVersion: true
133-
}, {
129+
}, {
134130
resize: {
135131
width: 500,
136132
type: 'scale',

packages/url/lib/url.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const extractPublicId = (link: string):string => {
1414
const parts = CLOUDINARY_REGEX.exec(link)
1515

1616
return parts && parts.length > 2 ? parts[parts.length - 2] : link
17-
}
17+
}
1818

1919
export const getSignature = (signature?: string) => {
2020
if (!signature) return ''
@@ -42,13 +42,13 @@ export const getSubDomain = (publicId: string, { cdnSubdomain = false, cname } :
4242
return cdnSubdomain ? `a${publicId}.` : ''
4343
}
4444

45-
export const getPrefix = (publicId: string, {
46-
cloudName,
47-
privateCdn = false,
48-
cdnSubdomain = false,
49-
secureDistribution,
50-
cname,
51-
secure = true,
45+
export const getPrefix = (publicId: string, {
46+
cloudName,
47+
privateCdn = false,
48+
cdnSubdomain = false,
49+
secureDistribution,
50+
cname,
51+
secure = true,
5252
}: CloudConfig):string => {
5353
const hasSecureDistribution = secure && secureDistribution && !SHARED_CDNS.includes(secureDistribution)
5454
const protocol = `http${secure ? 's' : ''}://`
@@ -95,11 +95,10 @@ export const getResourceType = ({
9595

9696
const isUrl = (str) => str && !!str.match(/^https?:\//)
9797

98-
export const getPathToAsset = (publicId: string, { urlSuffix = '', format = '' } : { urlSuffix?: string, format?: string }):string => {
98+
export const getPathToAsset = (publicId: string, { urlSuffix = '' } : { urlSuffix?: string }):string => {
9999
if (isUrl(publicId)) return encodePublicId(publicId)
100100

101-
const publicIdWithFormat = publicId.replace(/\.[^/.]+$/, format || '')
102-
const path = [publicIdWithFormat, urlSuffix].filter(Boolean).join('/')
101+
const path = [publicId, urlSuffix].filter(Boolean).join('/')
103102

104103
return encodePublicId(path)
105104
}
@@ -111,7 +110,7 @@ export const url = (publicId: string, cloud: CloudConfig = { cloudName: ''}, opt
111110

112111
//If publicId is cloudinary url, strip to get the publicId and version.
113112
const _publicId = isUrl(publicId) ? extractPublicId(publicId) : publicId
114-
113+
115114
//1. Get version
116115
const version:string = getVersion(_publicId, cloud)
117116
//2. Get Prefix
@@ -121,7 +120,7 @@ export const url = (publicId: string, cloud: CloudConfig = { cloudName: ''}, opt
121120
//4. Get Resource type
122121
const typePath:string = getResourceType(cloud)
123122
//5. Get path
124-
const pathToAsset:string = getPathToAsset(_publicId, { format: options.format, urlSuffix: cloud.urlSuffix })
123+
const pathToAsset:string = getPathToAsset(_publicId, { urlSuffix: cloud.urlSuffix })
125124
//6. Encode everything with %20 for whitespace
126125

127126
const format = options.fetchFormat || options.format || 'auto'

0 commit comments

Comments
 (0)