Add support for renew credentials (#27)
This commit is contained in:
1 parent
d8aadea2fe
commit
ada9fbe674
30 files changed
+228
-75
No files matched your search
@@ -94,6 +94,16 @@ export default defineComponent({
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
// check if the credential is created
|
||||
if (
|
||||
this.application &&
|
||||
!this.application?.credentials?.find((credential) => credential.host === window.location.origin)
|
||||
) {
|
||||
console.log('create extra credential');
|
||||
this.onCreateCredential(this.application);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onBuyMore(application: IApplication) {
|
||||
this.$router.push({
|
||||
@@ -103,6 +113,22 @@ export default defineComponent({
|
||||
}
|
||||
});
|
||||
},
|
||||
onCreateCredential(application: IApplication | undefined) {
|
||||
credentialOperator
|
||||
.create({
|
||||
application_id: application?.id,
|
||||
host: window.location.origin
|
||||
})
|
||||
.then(() => {
|
||||
setTimeout(() => {
|
||||
this.$emit('refresh');
|
||||
}, 2000);
|
||||
this.confirming = false;
|
||||
})
|
||||
.finally(() => {
|
||||
this.$emit('applied');
|
||||
});
|
||||
},
|
||||
onApply() {
|
||||
applicationOperator
|
||||
.create({
|
||||
@@ -111,19 +137,7 @@ export default defineComponent({
|
||||
})
|
||||
.then(({ data: data }: { data: IApplicationDetailResponse }) => {
|
||||
ElMessage.success(this.$t('application.message.applySuccessfully'));
|
||||
credentialOperator
|
||||
.create({
|
||||
application_id: data.id
|
||||
})
|
||||
.then(() => {
|
||||
setTimeout(() => {
|
||||
this.$emit('refresh');
|
||||
}, 2000);
|
||||
this.confirming = false;
|
||||
})
|
||||
.finally(() => {
|
||||
this.$emit('applied');
|
||||
});
|
||||
this.onCreateCredential(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error?.response?.data?.code === ERROR_CODE_DUPLICATION) {
|
||||
|
||||
@@ -159,7 +159,7 @@ textarea.input {
|
||||
background: none;
|
||||
box-shadow: none;
|
||||
resize: none;
|
||||
line-height: 30px;
|
||||
line-height: 35px;
|
||||
width: calc(100% - 80px);
|
||||
margin-left: 30px;
|
||||
}
|
||||
@@ -176,7 +176,7 @@ textarea.input:focus {
|
||||
background: none;
|
||||
box-shadow: none;
|
||||
resize: none;
|
||||
line-height: 30px;
|
||||
line-height: 35px;
|
||||
}
|
||||
}
|
||||
.el-upload-list {
|
||||
|
||||
@@ -96,7 +96,7 @@ export default defineComponent({
|
||||
return this.$store.state.chat.status.getConversations === Status.Request;
|
||||
},
|
||||
token() {
|
||||
return this.application?.credentials?.[0].token;
|
||||
return this.$store.state.chat?.credential?.token;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElSlider } from 'element-plus';
|
||||
import InfoIcon from '@/components/common/InfoIcon.vue';
|
||||
|
||||
const DEFAULT_IW = 1.0;
|
||||
import { MIDJOURNEY_DEFAULT_IMAGE_WEIGHT } from '@/constants';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ImageWeightSelector',
|
||||
@@ -35,7 +34,7 @@ export default defineComponent({
|
||||
},
|
||||
mounted() {
|
||||
if (!this.value) {
|
||||
this.value = DEFAULT_IW;
|
||||
this.value = MIDJOURNEY_DEFAULT_IMAGE_WEIGHT;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -21,8 +21,7 @@
|
||||
|
||||
<script>
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
const DEFAULT_RATIO = '1:1';
|
||||
import { MIDJOURNEY_DEFAULT_RATIO } from '@/constants';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'RatioSelector',
|
||||
@@ -81,7 +80,7 @@ export default defineComponent({
|
||||
},
|
||||
mounted() {
|
||||
if (!this.value) {
|
||||
this.value = DEFAULT_RATIO;
|
||||
this.value = MIDJOURNEY_DEFAULT_RATIO;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElSlider } from 'element-plus';
|
||||
import InfoIcon from '@/components/common/InfoIcon.vue';
|
||||
|
||||
const DEFAULT_STYLIZE = 100;
|
||||
import { MIDJOURNEY_DEFAULT_STYLIZE } from '@/constants';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'StylizeSelector',
|
||||
@@ -35,7 +34,7 @@ export default defineComponent({
|
||||
},
|
||||
mounted() {
|
||||
if (!this.value) {
|
||||
this.value = DEFAULT_STYLIZE;
|
||||
this.value = MIDJOURNEY_DEFAULT_STYLIZE;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElSlider } from 'element-plus';
|
||||
import InfoIcon from '@/components/common/InfoIcon.vue';
|
||||
|
||||
const DEFAULT_WEIRD = 0;
|
||||
import { MIDJOURNEY_DEFAULT_WIRED } from '@/constants';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'WeirdSelector',
|
||||
@@ -35,7 +34,7 @@ export default defineComponent({
|
||||
},
|
||||
mounted() {
|
||||
if (!this.value) {
|
||||
this.value = DEFAULT_WEIRD;
|
||||
this.value = MIDJOURNEY_DEFAULT_WIRED;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -63,6 +63,8 @@
|
||||
:preview-src-list="[modelValue?.response?.raw_image_url as string]"
|
||||
fit="contain"
|
||||
class="image"
|
||||
:lazy="true"
|
||||
@error="onReload($event)"
|
||||
/>
|
||||
<p v-if="modelValue?.response?.progress !== undefined && modelValue?.response?.progress !== 100" class="progress">
|
||||
{{ modelValue?.response?.progress }}%
|
||||
@@ -111,6 +113,7 @@ import {
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
|
||||
import { MIDJOURNEY_MODE_FAST, MIDJOURNEY_MODE_RELAX, MIDJOURNEY_MODE_TURBO } from '@/constants';
|
||||
import { parse } from 'path';
|
||||
|
||||
interface IData {
|
||||
midjourneyImagineState: typeof MidjourneyImagineState;
|
||||
@@ -222,6 +225,25 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onReload(event: Event) {
|
||||
const target = event.target as HTMLImageElement;
|
||||
// append a random url query to existing url query, to force reload the image
|
||||
// extract exiting url query
|
||||
const url = new URL(target.src);
|
||||
// extract `retry` query
|
||||
const retry = url.searchParams.get('retry');
|
||||
if (!retry) {
|
||||
// if no retry query, set it as random string
|
||||
url.searchParams.set('retry', '1');
|
||||
} else if (parseInt(retry) < 2) {
|
||||
// if retry < 3, increase it by 1
|
||||
url.searchParams.set('retry', (parseInt(retry) + 1).toString());
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
// set the new url
|
||||
target.src = url.toString();
|
||||
},
|
||||
onCustom(action: string) {
|
||||
this.$emit('custom', {
|
||||
action,
|
||||
|
||||
Reference in new issue
Block a user