Welcome to mirror list, hosted at ThFree Co, Russian Federation.

files.js « store « src - github.com/nextcloud/photos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 27f5cb03cef6ff60208ab8a230a66972ce4aed30 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
 * @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
 *
 * @author John Molakvoæ <skjnldsv@protonmail.com>
 *
 * @license AGPL-3.0-or-later
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
import Vue from 'vue'

const state = {
	files: {},
	nomediaPaths: [],
}

const mutations = {
	/**
	 * Append or update given files
	 *
	 * @param {object} state the store mutations
	 * @param {Array} files the store mutations
	 */
	updateFiles(state, files) {
		files.forEach(file => {
			if (state.nomediaPaths.some(nomediaPath => file.filename.startsWith(nomediaPath))) {
				return
			}
			if (file.fileid >= 0) {
				Vue.set(state.files, file.fileid, file)
			}
		})
	},

	/**
	 * Set a folder subfolders
	 *
	 * @param {object} state the store mutations
	 * @param {object} data destructuring object
	 * @param {number} data.fileid current folder id
	 * @param {Array} data.folders list of folders
	 */
	setSubFolders(state, { fileid, folders }) {
		if (state.files[fileid]) {
			const subfolders = folders
				.map(folder => folder.fileid)
				// some invalid folders have an id of -1 (ext storage)
				.filter(id => id >= 0)
			Vue.set(state.files[fileid], 'folders', subfolders)
		}
	},

	/**
	 * Set list of all .nomedia/.noimage files
	 *
	 * @param {object} state the store mutations
	 * @param {Array} paths list of files
	 */
	setNomediaPaths(state, paths) {
		state.nomediaPaths = paths
	},
}

const getters = {
	files: state => state.files,
	nomediaPaths: state => state.nomediaPaths,
}

const actions = {
	/**
	 * Update files, folders and their respective subfolders
	 *
	 * @param {object} context the store mutations
	 * @param {object} data destructuring object
	 * @param {object} data.folder current folder fileinfo
	 * @param {Array} data.files list of files
	 * @param {Array} data.folders list of folders within current folder
	 */
	updateFiles(context, { folder, files = [], folders = [] } = {}) {
		// we want all the FileInfo! Folders included!
		context.commit('updateFiles', [folder, ...files, ...folders])
		context.commit('setSubFolders', { fileid: folder.fileid, folders })
	},

	/**
	 * Append or update given files
	 *
	 * @param {object} context the store mutations
	 * @param {Array} files list of files
	 */
	appendFiles(context, files = []) {
		context.commit('updateFiles', files)
	},

	/**
	 * Set list of all .nomedia/.noimage files
	 *
	 * @param {object} context the store mutations
	 * @param {Array} paths list of files
	 */
	setNomediaPaths(context, paths) {
		console.debug('Ignored paths', { paths })
		context.commit('setNomediaPaths', paths)
	},
}

export default { state, mutations, getters, actions }