Finish ability to add files to versions and create new versions
This commit is contained in:
parent
663418e943
commit
7b4398dfee
@ -2,14 +2,14 @@
|
|||||||
<div>
|
<div>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
<input
|
<input
|
||||||
:id="id"
|
:id="inputId"
|
||||||
class="file-input"
|
class="file-input"
|
||||||
type="file"
|
type="file"
|
||||||
:accept="accept"
|
:accept="inputAccept"
|
||||||
:multiple="multiple"
|
:multiple="inputMultiple"
|
||||||
@change="onChange"
|
@change="onChange"
|
||||||
/>
|
/>
|
||||||
<label :for="id">{{ text }}</label>
|
<label :for="inputId">{{ text }}</label>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onChange(files) {
|
onChange(files) {
|
||||||
const length = files.target.length
|
const length = files.target.files.length
|
||||||
|
|
||||||
if (length === 0) {
|
if (length === 0) {
|
||||||
this.text = this.defaultText
|
this.text = this.defaultText
|
||||||
|
|||||||
@ -31,7 +31,6 @@ export default {
|
|||||||
border: none;
|
border: none;
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
cursor: pointer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.popup-body {
|
.popup-body {
|
||||||
@ -41,7 +40,7 @@ export default {
|
|||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
box-shadow: 0 2px 3px 1px var(--color-grey-2);
|
box-shadow: 0 2px 3px 1px var(--color-grey-2);
|
||||||
padding: 5px 60px 60px 20px;
|
padding: 5px 60px 5px 20px;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
max-height: 80%;
|
max-height: 80%;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
<button class="trash red">
|
<button class="trash red">
|
||||||
<TrashIcon />
|
<TrashIcon />
|
||||||
</button>
|
</button>
|
||||||
<button class="upload">
|
<button class="upload" @click="showPopup = !showPopup">
|
||||||
<UploadIcon />
|
<UploadIcon />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@ -46,6 +46,36 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<Popup :show-popup="showPopup">
|
||||||
|
<h3 class="popup-title">Upload Files</h3>
|
||||||
|
<div v-if="currentError" class="error">
|
||||||
|
<h4>Error</h4>
|
||||||
|
<p>{{ currentError }}</p>
|
||||||
|
</div>
|
||||||
|
<FileInput
|
||||||
|
input-id="version-files"
|
||||||
|
input-accept="application/*"
|
||||||
|
default-text="Upload Files"
|
||||||
|
:input-multiple="true"
|
||||||
|
@change="addFiles"
|
||||||
|
>
|
||||||
|
<label class="required" title="The files associated with the version">
|
||||||
|
Version Files
|
||||||
|
</label>
|
||||||
|
</FileInput>
|
||||||
|
<div class="popup-buttons">
|
||||||
|
<button
|
||||||
|
class="trash-button"
|
||||||
|
@click="
|
||||||
|
showPopup = false
|
||||||
|
filesToUpload = []
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<TrashIcon />
|
||||||
|
</button>
|
||||||
|
<button class="default-button" @click="uploadFiles">Upload</button>
|
||||||
|
</div>
|
||||||
|
</Popup>
|
||||||
</ModPage>
|
</ModPage>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
@ -55,6 +85,7 @@ import ModPage from '@/components/ModPage'
|
|||||||
import xss from 'xss'
|
import xss from 'xss'
|
||||||
import marked from 'marked'
|
import marked from 'marked'
|
||||||
|
|
||||||
|
import Popup from '@/components/Popup'
|
||||||
import DownloadIcon from '~/assets/images/utils/download.svg?inline'
|
import DownloadIcon from '~/assets/images/utils/download.svg?inline'
|
||||||
import UploadIcon from '~/assets/images/utils/upload.svg?inline'
|
import UploadIcon from '~/assets/images/utils/upload.svg?inline'
|
||||||
import TrashIcon from '~/assets/images/utils/trash.svg?inline'
|
import TrashIcon from '~/assets/images/utils/trash.svg?inline'
|
||||||
@ -64,6 +95,7 @@ import FabricIcon from '~/assets/images/categories/fabric.svg?inline'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
Popup,
|
||||||
ModPage,
|
ModPage,
|
||||||
ForgeIcon,
|
ForgeIcon,
|
||||||
FabricIcon,
|
FabricIcon,
|
||||||
@ -113,6 +145,59 @@ export default {
|
|||||||
changelog,
|
changelog,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
showPopup: false,
|
||||||
|
currentError: null,
|
||||||
|
filesToUpload: [],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
addFiles(e) {
|
||||||
|
this.filesToUpload = e.target.files
|
||||||
|
|
||||||
|
for (let i = 0; i < e.target.files.length; i++) {
|
||||||
|
this.filesToUpload[i].multipartName = e.target.files[i].name.concat(
|
||||||
|
'-' + i
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async uploadFiles() {
|
||||||
|
this.$nuxt.$loading.start()
|
||||||
|
this.currentError = null
|
||||||
|
|
||||||
|
const formData = new FormData()
|
||||||
|
|
||||||
|
formData.append('data', JSON.stringify({}))
|
||||||
|
|
||||||
|
for (const fileToUpload in this.filesToUpload) {
|
||||||
|
formData.append(
|
||||||
|
fileToUpload.multipartName,
|
||||||
|
new Blob([fileToUpload]),
|
||||||
|
fileToUpload.name
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await axios({
|
||||||
|
url: `https://api.modrinth.com/api/v1/version/${this.version.id}/file`,
|
||||||
|
method: 'POST',
|
||||||
|
data: formData,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data',
|
||||||
|
Authorization: this.$auth.getToken('local'),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
await this.$router.go(null)
|
||||||
|
} catch (err) {
|
||||||
|
this.currentError = err.response.data.description
|
||||||
|
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$nuxt.$loading.finish()
|
||||||
|
},
|
||||||
|
},
|
||||||
head() {
|
head() {
|
||||||
return {
|
return {
|
||||||
title: this.mod.title + ' - Modrinth - Files',
|
title: this.mod.title + ' - Modrinth - Files',
|
||||||
@ -265,4 +350,45 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.popup-title {
|
||||||
|
margin-bottom: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.popup-buttons {
|
||||||
|
margin-top: 40px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: left;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
.default-button {
|
||||||
|
border-radius: var(--size-rounded-sm);
|
||||||
|
cursor: pointer;
|
||||||
|
border: none;
|
||||||
|
padding: 10px;
|
||||||
|
background-color: var(--color-grey-1);
|
||||||
|
color: var(--color-grey-5);
|
||||||
|
|
||||||
|
&:hover,
|
||||||
|
&:focus {
|
||||||
|
color: var(--color-grey-4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.trash-button {
|
||||||
|
cursor: pointer;
|
||||||
|
margin-right: 10px;
|
||||||
|
padding: 5px;
|
||||||
|
border: none;
|
||||||
|
border-radius: var(--size-rounded-sm);
|
||||||
|
color: #9b2c2c;
|
||||||
|
background-color: var(--color-bg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
margin: 20px 0;
|
||||||
|
border-left: #e04e3e 7px solid;
|
||||||
|
padding: 5px 20px 20px 20px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -54,7 +54,10 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<Popup
|
<Popup
|
||||||
v-if="showPopup"
|
v-if="
|
||||||
|
this.$auth.loggedIn &&
|
||||||
|
members.find((x) => x.user_id === this.$auth.user.id)
|
||||||
|
"
|
||||||
:show-popup="showPopup"
|
:show-popup="showPopup"
|
||||||
class="create-version-popup-body"
|
class="create-version-popup-body"
|
||||||
>
|
>
|
||||||
@ -441,7 +444,6 @@ input {
|
|||||||
|
|
||||||
.popup-buttons {
|
.popup-buttons {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
margin-left: auto;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: right;
|
justify-content: right;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@ -18,10 +18,10 @@
|
|||||||
alt="preview-image"
|
alt="preview-image"
|
||||||
/>
|
/>
|
||||||
<FileInput
|
<FileInput
|
||||||
id="icon-file"
|
input-id="icon-file"
|
||||||
accept="image/x-png,image/gif,image/jpeg"
|
input-accept="image/*"
|
||||||
default-text="Upload Icon"
|
default-text="Upload Icon"
|
||||||
:multiple="false"
|
:input-multiple="false"
|
||||||
@change="showPreviewImage"
|
@change="showPreviewImage"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -203,16 +203,17 @@
|
|||||||
v-model="versions[currentVersionIndex].version_body"
|
v-model="versions[currentVersionIndex].version_body"
|
||||||
class="changelog-editor"
|
class="changelog-editor"
|
||||||
/>
|
/>
|
||||||
<label class="required" title="The files associated with the version">
|
|
||||||
Version Files
|
|
||||||
</label>
|
|
||||||
<FileInput
|
<FileInput
|
||||||
input-id="version-files"
|
input-id="version-files"
|
||||||
input-accept="application/java-archive,application/zip"
|
input-accept="application/*"
|
||||||
:input-multiple="true"
|
:input-multiple="true"
|
||||||
default-text="Upload Files"
|
default-text="Upload Files"
|
||||||
@change="updateVersionFiles"
|
@change="updateVersionFiles"
|
||||||
/>
|
>
|
||||||
|
<label class="required" title="The files associated with the version">
|
||||||
|
Version Files
|
||||||
|
</label>
|
||||||
|
</FileInput>
|
||||||
</Popup>
|
</Popup>
|
||||||
<div class="versions-header">
|
<div class="versions-header">
|
||||||
<h3>Versions</h3>
|
<h3>Versions</h3>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user