Skip to content

Commit 88423bc

Browse files
authored
Merge pull request #4 from BlueprintFramework/direct-platform-urls
Direct platform urls
2 parents c7b0a8a + 74b3bdf commit 88423bc

File tree

5 files changed

+66
-101
lines changed

5 files changed

+66
-101
lines changed

apps/backend/src/routes/user/admin/extensions/_extension_/mod.rs

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ mod get {
9999
mod patch {
100100
use crate::{
101101
models::extension::{
102-
ExtensionPlatform, ExtensionPlatformData, ExtensionStatus, ExtensionType,
103-
MinimalExtensionPlatformData,
102+
ExtensionPlatform, ExtensionPlatformCurrency, ExtensionPlatformData, ExtensionStatus,
103+
ExtensionType,
104104
},
105105
response::{ApiResponse, ApiResponseResult},
106106
routes::{ApiError, GetState, user::admin::extensions::_extension_::GetExtension},
@@ -132,7 +132,8 @@ mod patch {
132132
#[validate(length(max = 1024))]
133133
#[schema(max_length = 1024)]
134134
description: Option<String>,
135-
platforms: Option<BTreeMap<ExtensionPlatform, MinimalExtensionPlatformData>>,
135+
#[schema(value_type = Option<BTreeMap<ExtensionPlatform, String>>)]
136+
platforms: Option<BTreeMap<ExtensionPlatform, reqwest::Url>>,
136137
}
137138

138139
#[derive(ToSchema, Serialize)]
@@ -169,12 +170,7 @@ mod patch {
169170
}
170171
}
171172
if let Some(mut platforms) = data.platforms {
172-
if let Some(builtbybit) = platforms.remove(&ExtensionPlatform::Builtbybit) {
173-
let url = match reqwest::Url::parse(&builtbybit.url) {
174-
Ok(url) => url,
175-
Err(_) => return ApiResponse::error("invalid builtbybit url").ok(),
176-
};
177-
173+
if let Some(url) = platforms.remove(&ExtensionPlatform::Builtbybit) {
178174
if url.host_str() != Some("builtbybit.com")
179175
|| !url.path().starts_with("/resources/")
180176
{
@@ -201,29 +197,22 @@ mod patch {
201197

202198
if let Some(platform) = extension.platforms.get_mut(&ExtensionPlatform::Builtbybit)
203199
{
204-
platform.url = builtbybit.url;
205-
platform.price = builtbybit.price;
206-
platform.currency = builtbybit.currency;
200+
platform.url = url.to_string();
207201
} else {
208202
extension.platforms.insert(
209203
ExtensionPlatform::Builtbybit,
210204
ExtensionPlatformData {
211-
url: builtbybit.url,
212-
price: builtbybit.price,
213-
currency: builtbybit.currency,
205+
url: url.to_string(),
206+
price: 0.0,
207+
currency: ExtensionPlatformCurrency::Usd,
214208
reviews: None,
215209
rating: None,
216210
},
217211
);
218212
}
219213
}
220214

221-
if let Some(sourcexchange) = platforms.remove(&ExtensionPlatform::Sourcexchange) {
222-
let url = match reqwest::Url::parse(&sourcexchange.url) {
223-
Ok(url) => url,
224-
Err(_) => return ApiResponse::error("invalid sourcexchange url").ok(),
225-
};
226-
215+
if let Some(url) = platforms.remove(&ExtensionPlatform::Sourcexchange) {
227216
if url.host_str() != Some("www.sourcexchange.net")
228217
|| !url.path().starts_with("/products/")
229218
{
@@ -234,29 +223,22 @@ mod patch {
234223
.platforms
235224
.get_mut(&ExtensionPlatform::Sourcexchange)
236225
{
237-
platform.url = sourcexchange.url;
238-
platform.price = sourcexchange.price;
239-
platform.currency = sourcexchange.currency;
226+
platform.url = url.to_string();
240227
} else {
241228
extension.platforms.insert(
242229
ExtensionPlatform::Sourcexchange,
243230
ExtensionPlatformData {
244-
url: sourcexchange.url,
245-
price: sourcexchange.price,
246-
currency: sourcexchange.currency,
231+
url: url.to_string(),
232+
price: 0.0,
233+
currency: ExtensionPlatformCurrency::Usd,
247234
reviews: None,
248235
rating: None,
249236
},
250237
);
251238
}
252239
}
253240

254-
if let Some(github) = platforms.remove(&ExtensionPlatform::Github) {
255-
let url = match reqwest::Url::parse(&github.url) {
256-
Ok(url) => url,
257-
Err(_) => return ApiResponse::error("invalid github url").ok(),
258-
};
259-
241+
if let Some(url) = platforms.remove(&ExtensionPlatform::Github) {
260242
if url.host_str() != Some("github.com") {
261243
return ApiResponse::error("invalid github url").ok();
262244
}
@@ -271,16 +253,14 @@ mod patch {
271253
}
272254

273255
if let Some(platform) = extension.platforms.get_mut(&ExtensionPlatform::Github) {
274-
platform.url = github.url;
275-
platform.price = github.price;
276-
platform.currency = github.currency;
256+
platform.url = url.to_string();
277257
} else {
278258
extension.platforms.insert(
279259
ExtensionPlatform::Github,
280260
ExtensionPlatformData {
281-
url: github.url,
282-
price: github.price,
283-
currency: github.currency,
261+
url: url.to_string(),
262+
price: 0.0,
263+
currency: ExtensionPlatformCurrency::Usd,
284264
reviews: None,
285265
rating: None,
286266
},

apps/backend/src/routes/user/extensions/_extension_/mod.rs

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ mod get {
104104
mod patch {
105105
use crate::{
106106
models::extension::{
107-
ExtensionPlatform, ExtensionPlatformData, ExtensionStatus, ExtensionType,
108-
MinimalExtensionPlatformData,
107+
ExtensionPlatform, ExtensionPlatformCurrency, ExtensionPlatformData, ExtensionStatus,
108+
ExtensionType,
109109
},
110110
response::{ApiResponse, ApiResponseResult},
111111
routes::{ApiError, GetState, user::extensions::_extension_::GetExtension},
@@ -137,7 +137,8 @@ mod patch {
137137
#[validate(length(max = 1024))]
138138
#[schema(max_length = 1024)]
139139
description: Option<String>,
140-
platforms: Option<BTreeMap<ExtensionPlatform, MinimalExtensionPlatformData>>,
140+
#[schema(value_type = Option<BTreeMap<ExtensionPlatform, String>>)]
141+
platforms: Option<BTreeMap<ExtensionPlatform, reqwest::Url>>,
141142
}
142143

143144
#[derive(ToSchema, Serialize)]
@@ -174,12 +175,7 @@ mod patch {
174175
}
175176
}
176177
if let Some(mut platforms) = data.platforms {
177-
if let Some(builtbybit) = platforms.remove(&ExtensionPlatform::Builtbybit) {
178-
let url = match reqwest::Url::parse(&builtbybit.url) {
179-
Ok(url) => url,
180-
Err(_) => return ApiResponse::error("invalid builtbybit url").ok(),
181-
};
182-
178+
if let Some(url) = platforms.remove(&ExtensionPlatform::Builtbybit) {
183179
if url.host_str() != Some("builtbybit.com")
184180
|| !url.path().starts_with("/resources/")
185181
{
@@ -206,29 +202,22 @@ mod patch {
206202

207203
if let Some(platform) = extension.platforms.get_mut(&ExtensionPlatform::Builtbybit)
208204
{
209-
platform.url = builtbybit.url;
210-
platform.price = builtbybit.price;
211-
platform.currency = builtbybit.currency;
205+
platform.url = url.to_string();
212206
} else {
213207
extension.platforms.insert(
214208
ExtensionPlatform::Builtbybit,
215209
ExtensionPlatformData {
216-
url: builtbybit.url,
217-
price: builtbybit.price,
218-
currency: builtbybit.currency,
210+
url: url.to_string(),
211+
price: 0.0,
212+
currency: ExtensionPlatformCurrency::Usd,
219213
reviews: None,
220214
rating: None,
221215
},
222216
);
223217
}
224218
}
225219

226-
if let Some(sourcexchange) = platforms.remove(&ExtensionPlatform::Sourcexchange) {
227-
let url = match reqwest::Url::parse(&sourcexchange.url) {
228-
Ok(url) => url,
229-
Err(_) => return ApiResponse::error("invalid sourcexchange url").ok(),
230-
};
231-
220+
if let Some(url) = platforms.remove(&ExtensionPlatform::Sourcexchange) {
232221
if url.host_str() != Some("www.sourcexchange.net")
233222
|| !url.path().starts_with("/products/")
234223
{
@@ -239,29 +228,22 @@ mod patch {
239228
.platforms
240229
.get_mut(&ExtensionPlatform::Sourcexchange)
241230
{
242-
platform.url = sourcexchange.url;
243-
platform.price = sourcexchange.price;
244-
platform.currency = sourcexchange.currency;
231+
platform.url = url.to_string();
245232
} else {
246233
extension.platforms.insert(
247234
ExtensionPlatform::Sourcexchange,
248235
ExtensionPlatformData {
249-
url: sourcexchange.url,
250-
price: sourcexchange.price,
251-
currency: sourcexchange.currency,
236+
url: url.to_string(),
237+
price: 0.0,
238+
currency: ExtensionPlatformCurrency::Usd,
252239
reviews: None,
253240
rating: None,
254241
},
255242
);
256243
}
257244
}
258245

259-
if let Some(github) = platforms.remove(&ExtensionPlatform::Github) {
260-
let url = match reqwest::Url::parse(&github.url) {
261-
Ok(url) => url,
262-
Err(_) => return ApiResponse::error("invalid github url").ok(),
263-
};
264-
246+
if let Some(url) = platforms.remove(&ExtensionPlatform::Github) {
265247
if url.host_str() != Some("github.com") {
266248
return ApiResponse::error("invalid github url").ok();
267249
}
@@ -276,16 +258,14 @@ mod patch {
276258
}
277259

278260
if let Some(platform) = extension.platforms.get_mut(&ExtensionPlatform::Github) {
279-
platform.url = github.url;
280-
platform.price = github.price;
281-
platform.currency = github.currency;
261+
platform.url = url.to_string();
282262
} else {
283263
extension.platforms.insert(
284264
ExtensionPlatform::Github,
285265
ExtensionPlatformData {
286-
url: github.url,
287-
price: github.price,
288-
currency: github.currency,
266+
url: url.to_string(),
267+
price: 0.0,
268+
currency: ExtensionPlatformCurrency::Usd,
289269
reviews: None,
290270
rating: None,
291271
},

apps/frontend/src/components/ui/app/extensions/Platformsmodal.vue

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ const { rules } = useFormValidation()
122122
123123
interface Props {
124124
isOpen: boolean
125-
platforms: ExtensionPlatforms
125+
platforms: ExtensionPlatformUrls
126126
}
127127
128128
const props = defineProps<Props>()
129129
const emit = defineEmits<{
130130
close: []
131-
save: [platforms: ExtensionPlatforms]
131+
save: [platforms: ExtensionPlatformUrls]
132132
}>()
133133
134134
const fieldValidation = ref<Record<string, boolean>>({})
@@ -160,52 +160,40 @@ watch(
160160
}
161161
162162
localUrls.value = {
163-
BUILTBYBIT: props.platforms.BUILTBYBIT?.url || '',
164-
SOURCEXCHANGE: props.platforms.SOURCEXCHANGE?.url || '',
165-
GITHUB: props.platforms.GITHUB?.url || '',
163+
BUILTBYBIT: props.platforms.BUILTBYBIT || '',
164+
SOURCEXCHANGE: props.platforms.SOURCEXCHANGE || '',
165+
GITHUB: props.platforms.GITHUB || '',
166166
}
167167
}
168168
},
169169
{ immediate: true }
170170
)
171171
172172
const handleClose = () => {
173-
const platforms: ExtensionPlatforms = {}
173+
const platforms: ExtensionPlatformUrls = {}
174174
175175
if (
176176
localEnabled.value.BUILTBYBIT &&
177177
localUrls.value.BUILTBYBIT &&
178178
fieldValidation.value.builtbybit_url !== false
179179
) {
180-
platforms.BUILTBYBIT = {
181-
url: localUrls.value.BUILTBYBIT,
182-
price: props.platforms.BUILTBYBIT?.price ?? 0,
183-
currency: props.platforms.BUILTBYBIT?.currency ?? 'USD',
184-
}
180+
platforms.BUILTBYBIT = localUrls.value.BUILTBYBIT
185181
}
186182
187183
if (
188184
localEnabled.value.SOURCEXCHANGE &&
189185
localUrls.value.SOURCEXCHANGE &&
190186
fieldValidation.value.sourcexchange_url !== false
191187
) {
192-
platforms.SOURCEXCHANGE = {
193-
url: localUrls.value.SOURCEXCHANGE,
194-
price: props.platforms.SOURCEXCHANGE?.price ?? 0,
195-
currency: props.platforms.SOURCEXCHANGE?.currency ?? 'USD',
196-
}
188+
platforms.SOURCEXCHANGE = localUrls.value.SOURCEXCHANGE
197189
}
198190
199191
if (
200192
localEnabled.value.GITHUB &&
201193
localUrls.value.GITHUB &&
202194
fieldValidation.value.github_url !== false
203195
) {
204-
platforms.GITHUB = {
205-
url: localUrls.value.GITHUB,
206-
price: props.platforms.GITHUB?.price ?? 0,
207-
currency: props.platforms.GITHUB?.currency ?? 'USD',
208-
}
196+
platforms.GITHUB = localUrls.value.GITHUB
209197
}
210198
211199
emit('save', platforms)

apps/frontend/src/pages/app/extensions/[id].vue

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ const modalOpen = ref({
517517
const form = ref<{
518518
identifier: string
519519
name: string
520-
platforms: ExtensionPlatforms
520+
platforms: ExtensionPlatformUrls
521521
summary: string
522522
type: ExtensionType
523523
unlisted: boolean
@@ -568,12 +568,23 @@ watch(
568568
form.value = {
569569
identifier: newData.extension.identifier || '',
570570
name: newData.extension.name || '',
571-
platforms: newData.extension.platforms || {},
571+
platforms: form.value.platforms,
572572
summary: newData.extension.summary || '',
573573
type: newData.extension.type || 'extension',
574574
unlisted: newData.extension.unlisted,
575575
description: newData.extension.description || '',
576576
}
577+
578+
const urls: ExtensionPlatformUrls = {}
579+
for (const key in newData.extension.platforms) {
580+
if (
581+
Object.prototype.hasOwnProperty.call(newData.extension.platforms, key)
582+
) {
583+
urls[key] = newData.extension.platforms[key]?.url || ''
584+
}
585+
}
586+
587+
form.value.platforms = urls
577588
}
578589
},
579590
{ immediate: true }
@@ -675,6 +686,9 @@ const handleDelete = async () => {
675686
676687
const handlePlatformsSave = (platforms: ExtensionPlatforms) => {
677688
form.value.platforms = platforms
689+
690+
if (platforms.GITHUB) {
691+
}
678692
}
679693
680694
const handleAdminApprove = async () => {

apps/frontend/src/types/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export interface ExtensionFullPlatform extends ExtensionPlatform {
4040
rating?: number | null
4141
}
4242

43+
export type ExtensionPlatformUrls = Record<string, ExtensionPlatformUrl>
44+
export type ExtensionPlatformUrl = string
45+
4346
export interface ExtensionBanner {
4447
fullres: string
4548
lowres: string

0 commit comments

Comments
 (0)