+
+
@@ -9,16 +9,17 @@
-
-
-
- {{ $t('suno.button.generate') }}
-
-
-
- {{ $t('suno.button.extend') }}
-
-
+
+
+
+
+
+ {{ $t('suno.button.generate') }}
+
+
+
+ {{ $t('suno.button.extend') }}
+
@@ -35,6 +36,8 @@ import TitleInput from './config/TitleInput.vue';
import ExtendFromInput from './config/ExtendFromInput.vue';
import CoverFromInput from './config/CoverFromInput.vue';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
+import Consumption from '../common/Consumption.vue';
+import { getConsumption } from '@/utils';
export default defineComponent({
name: 'PresetPanel',
@@ -48,12 +51,19 @@ export default defineComponent({
CoverFromInput,
UploadAudio,
FontAwesomeIcon,
- ElButton
+ ElButton,
+ Consumption
},
emits: ['generate'],
computed: {
config() {
return this.$store.state.suno?.config;
+ },
+ consumption() {
+ return getConsumption(this.config, this.service?.metadata?.price);
+ },
+ service() {
+ return this.$store.state.suno?.service;
}
},
methods: {
diff --git a/src/models/service.ts b/src/models/service.ts
index 05834a94..c5327c8c 100644
--- a/src/models/service.ts
+++ b/src/models/service.ts
@@ -10,6 +10,7 @@ export interface IService {
applied_count?: number;
applied?: boolean;
tags?: string[];
+ metadata?: any;
thumbnail?: string;
introduction?: string;
apis?: IApi[];
diff --git a/src/utils/price.ts b/src/utils/price.ts
index d1da4b58..96f188aa 100644
--- a/src/utils/price.ts
+++ b/src/utils/price.ts
@@ -1,5 +1,6 @@
import { CURRENCY_LABEL_MAPPING } from '@/constants/mapping';
import store from '@/store';
+import jsonLogic from 'json-logic-js';
/**
* Input a value and target currency (e.g. cny), return the price which the current locale
@@ -45,3 +46,16 @@ export const getPriceString = (payload: {
});
return `${price.label}${price.value?.toFixed(fractionDigits)}`;
};
+
+export const getConsumption = (payload: any, rules: any): number | undefined => {
+ if (!rules || !Array.isArray(rules)) {
+ return undefined;
+ }
+ for (const rule of rules) {
+ const conditions = rule.conditions;
+ if (jsonLogic.apply(conditions, payload)) {
+ return jsonLogic.apply(rule.consumption) as number;
+ }
+ }
+ return 0;
+};
diff --git a/yarn.lock b/yarn.lock
index d09c1999..b5855a7f 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1122,6 +1122,11 @@
"@types/minimatch" "^5.1.2"
"@types/node" "*"
+"@types/json-logic-js@^2.0.8":
+ version "2.0.8"
+ resolved "https://registry.yarnpkg.com/@types/json-logic-js/-/json-logic-js-2.0.8.tgz#a1108452069a498981813e32dd081754ae6b3395"
+ integrity sha512-WgNsDPuTPKYXl0Jh0IfoCoJoAGGYZt5qzpmjuLSEg7r0cKp/kWtWp0HAsVepyPSPyXiHo6uXp/B/kW/2J1fa2Q==
+
"@types/json-schema@^7.0.9":
version "7.0.15"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841"
@@ -3677,6 +3682,11 @@ json-buffer@3.0.1:
resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.1.tgz#9338802a30d3b6605fbe0613e094008ca8c05a13"
integrity sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==
+json-logic-js@^2.0.5:
+ version "2.0.5"
+ resolved "https://registry.yarnpkg.com/json-logic-js/-/json-logic-js-2.0.5.tgz#55f0c687dd6f56b02ccdcfdd64171ed998ab5499"
+ integrity sha512-rTT2+lqcuUmj4DgWfmzupZqQDA64AdmYqizzMPWj3DxGdfFNsxPpcNVSaTj4l8W2tG/+hg7/mQhxjU3aPacO6g==
+
json-parse-even-better-errors@^2.3.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz#7c47805a94319928e05777405dc12e1f7a4ee02d"