summaryrefslogtreecommitdiff
path: root/components/FilePreview.vue
blob: 389285739199c367d3d54c1eef059091fc76734a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<template lang="pug">
  .file-preview.h-full.overflow-hidden.grid.items-center
    img.block.mx-auto(
      v-if="isImage(path)"
      :src="baseAPI + '' + path"
    )
    model-stl(
      v-else-if="isStl(path)"
      :rotate="rotate"
      :src="baseAPI + '' + path"
      :backgroundColor="bg ? bg : '#D1D5DB'"
      :controlsOptions="{'enablePan': controls ? true : false, 'enableZoom': controls ? true : false, 'enableRotate': controls ? true : false}"
    )
    model-obj(
      v-else-if="isObj(path)"
      :src="baseAPI + '' + path"
      :backgroundColor="bg ? bg : '#D1D5DB'"
      :controlsOptions="{'enablePan': controls ? true : false, 'enableZoom': controls ? true : false, 'enableRotate': controls ? true : false}"
    )
</template>

<script>
import { ModelStl, ModelObj } from "vue-3d-model";

export default {
  name: "FilePreview",
  props: ["path", "bg", "controls"],
  data() {
    return {
      baseAPI: "",
      rotate: {
        x: -Math.PI / 2,
        y: 0,
        z: 0,
      },
    };
  },
  components: {
    ModelStl,
    ModelObj,
  },
  created() {
    this.baseAPI = this.$config.api;
  },
  methods: {
    checkExt(path, ext) {
      return path.indexOf("." + ext) > 0;
    },
    isImage(path) {
      return (
        this.checkExt(path, "png") ||
        this.checkExt(path, "jpg") ||
        this.checkExt(path, "jpeg") ||
        this.checkExt(path, "webp")
      );
    },
    isStl(path) {
      return this.checkExt(path, "stl") || this.checkExt(path, "sla");
    },
    isObj(path) {
      return this.checkExt(path, "obj") || this.checkExt(path, "octet-stream");
    },
  },
};
</script>