-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* l2s init * [Components] l2s #14107 Actions - Create Shortened URL * pnpm update
- Loading branch information
1 parent
c6bcdf0
commit bfbec2e
Showing
5 changed files
with
147 additions
and
7 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
components/l2s/actions/create-shortened-url/create-shortened-url.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { parseObject } from "../../common/utils.mjs"; | ||
import l2s from "../../l2s.app.mjs"; | ||
|
||
export default { | ||
key: "l2s-create-shortened-url", | ||
name: "Create Shortened URL", | ||
description: "Generates a shortened URL utilizing L2S capabilities. [See the documentation](https://docs.l2s.is/)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
l2s, | ||
url: { | ||
type: "string", | ||
label: "URL", | ||
description: "The URL to be shortened", | ||
}, | ||
customKey: { | ||
type: "string", | ||
label: "Custom Key", | ||
description: "Custom key for the shortened URL", | ||
optional: true, | ||
}, | ||
utmSource: { | ||
type: "string", | ||
label: "UTM Source", | ||
description: "UTM source parameter", | ||
optional: true, | ||
}, | ||
utmMedium: { | ||
type: "string", | ||
label: "UTM Medium", | ||
description: "UTM medium parameter", | ||
optional: true, | ||
}, | ||
utmCampaign: { | ||
type: "string", | ||
label: "UTM Campaign", | ||
description: "UTM campaign parameter", | ||
optional: true, | ||
}, | ||
utmTerm: { | ||
type: "string", | ||
label: "UTM Term", | ||
description: "UTM term parameter", | ||
optional: true, | ||
}, | ||
utmContent: { | ||
type: "string", | ||
label: "UTM Content", | ||
description: "UTM content parameter", | ||
optional: true, | ||
}, | ||
title: { | ||
type: "string", | ||
label: "Title", | ||
description: "Title for the shortened URL", | ||
optional: true, | ||
}, | ||
tags: { | ||
type: "string[]", | ||
label: "Tags", | ||
description: "Tags associated with the URL", | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
l2s, | ||
tags, | ||
...data | ||
} = this; | ||
|
||
if (tags) { | ||
data.tags = parseObject(tags); | ||
} | ||
|
||
const { response: { data: response } } = await l2s.shortenUrl({ | ||
$, | ||
data, | ||
}); | ||
|
||
const shortUrl = `https://l2s.is/${response.key}`; | ||
$.export("$summary", "URL shortened successfully"); | ||
return { | ||
short_url: shortUrl, | ||
...response, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export const parseObject = (obj) => { | ||
if (!obj) return undefined; | ||
|
||
if (Array.isArray(obj)) { | ||
return obj.map((item) => { | ||
if (typeof item === "string") { | ||
try { | ||
return JSON.parse(item); | ||
} catch (e) { | ||
return item; | ||
} | ||
} | ||
return item; | ||
}); | ||
} | ||
if (typeof obj === "string") { | ||
try { | ||
return JSON.parse(obj); | ||
} catch (e) { | ||
return obj; | ||
} | ||
} | ||
return obj; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,32 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "l2s", | ||
propDefinitions: {}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return "https://api.l2s.is"; | ||
}, | ||
_headers() { | ||
return { | ||
Authorization: `Bearer ${this.$auth.api_key}`, | ||
}; | ||
}, | ||
_makeRequest({ | ||
$ = this, path, ...opts | ||
}) { | ||
return axios($, { | ||
url: this._baseUrl() + path, | ||
headers: this._headers(), | ||
...opts, | ||
}); | ||
}, | ||
shortenUrl(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: "/url", | ||
...opts, | ||
}); | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@pipedream/l2s", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream L2S Components", | ||
"main": "l2s.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.1" | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.