import axios from 'axios'

export default {
  namespaced: true,
  actions: {
    async addFile ({rootState}, {file}) { // 新增檔案
      try {
        let result = await axios.post(`/file/project/${rootState.project.current._id}`, {
          name: file.name,
          mime: file.type,
          size: file.size
        })
        await axios.put(result.headers['location'].replace("/post-webapi", ""), file, {
          headers: {
            'Content-Type': file.type
          }
        })
      } catch (err) {
        throw err
      }
    }
  }
}
