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

EnhancedPassword.js « Password « Model « src - git.mdns.eu/nextcloud/passwords-client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9290910e23c578d303f56834b59a8a3d2373aac4 (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
120
121
122
123
124
125
126
127
128
129
130
import Password from './Password';
import Url from 'url-parse';

export default class EnhancedPassword extends Password {

    /**
     *
     * @param {BasicPasswordsClient} api
     * @param {Object} [data={}]
     */
    constructor(data = {}, api) {
        super(data);
        this._api = api;
    }

    /**
     *
     * @returns {Server}
     */
    getServer() {
        return this._api.getServer();
    }

    /**
     *
     * @param {Number} [size=32]
     * @param {Boolean} [pathOnly=false]
     * @return {String}
     */
    getFaviconUrl(size = 32, pathOnly = false) {
        let host = 'default';

        if(this.getUrl()) {
            let url = Url(this.getUrl());

            if(url.host.length !== 0) {
                host = url.host;
            }
        }

        if(pathOnly) return `1.0/service/favicon/${host}/${size}`;

        return `${this.getServer().getApiUrl()}1.0/service/favicon/${host}/${size}`;
    }

    /**
     *
     * @param size
     * @returns {Promise<Blob>}
     */
    async getFavicon(size = 32) {
        let path = this.getFaviconUrl(size, true),
            response = await this._api.getRequest().setPath(path).setResponseType('image/png').send();

        return response.getData();
    }

    /**
     *
     * @param {(String|Number)} width
     * @param {(String|Number)} height
     * @param {String} view
     * @param {Boolean} [pathOnly=false]
     * @return {String}
     */
    getPreviewUrl(width = 640, height = '360...', view = 'desktop', pathOnly = false) {
        let host = 'default';

        if(this.getUrl()) {
            let url = Url(this.getUrl());

            if(url.host.length !== 0) {
                host = url.host;
            }
        }

        if(pathOnly) return `1.0/service/preview/${host}/${view}/${width}/${height}`;

        return `${this.getServer().getApiUrl()}1.0/service/preview/${host}/${view}/${width}/${height}`;
    }

    /**
     *
     * @param {(String|Number)} width
     * @param {(String|Number)} height
     * @param {String} view
     * @returns {Promise<Blob>}
     */
    async getPreview(width = 640, height = '360...', view) {
        let path = this.getPreviewUrl(width, height, view, true),
            response = await this._api.getRequest().setPath(path).setResponseType('image/jpeg').send();

        return response.getData();
    }

    /**
     *
     * @returns {Promise<PasswordCollection>}
     */
    async fetchRevisions() {
    }

    /**
     *
     * @returns {Promise<Share>}
     */
    async fetchShare() {
    }

    /**
     *
     * @returns {Promise<ShareCollection>}
     */
    async fetchShares() {
    }

    /**
     *
     * @returns {Promise<TagCollection>}
     */
    async fetchTags() {
    }

    /**
     *
     * @returns {Promise<FolderCollection>}
     */
    async fetchFolder() {
    }
}