import axios from '../plugins/axios'
import { defineStore } from 'pinia'

export const useUploaderStore = defineStore('uploader', {
    state: () => ({

    }),


    actions: {
        async uploader(file) {
            
            const form = new FormData()

            form.append('directoryName', 'directoryName')
            form.append('file',  file)
          
            let config = {
                headers: {
                    "Content-Type": "multipart/form-data",
                },
                
            };
            try {
                const result = await axios.post('/uploader',
                    form,
                    config
                );
       
          
                return result;
            } catch (error) {
       
                return error;
            }
        },
async getUrl(fileName){
    const data = await axios.get(`/uploader/file?fileName=${fileName}`)
    return data
},


        async bulk(files) {
            const form = new FormData()
            files.forEach(file => form.append('images', file))

            const params = { type: 1 }

            const result = await axios.post('/images/admin/upload', form, { params })

            return result;
        }
    }
})