mirror of
https://github.com/trympet/nextcloud-artifacts-action.git
synced 2025-07-27 03:13:18 +02:00
more cleanup
This commit is contained in:
@@ -1,30 +1,27 @@
|
||||
import * as core from '@actions/core'
|
||||
import { NoFileOption } from './NoFileOption'
|
||||
import { Inputs } from './Inputs'
|
||||
import { URL } from 'url'
|
||||
|
||||
export class ActionInputs implements Inputs {
|
||||
get ArtifactName(): string {
|
||||
return core.getInput('name')
|
||||
return core.getInput('name', { required: false }) || 'Nextcloud Artifact'
|
||||
}
|
||||
|
||||
get ArtifactPath(): string {
|
||||
return core.getInput('path')
|
||||
return core.getInput('path', { required: true })
|
||||
}
|
||||
|
||||
get Retention(): string {
|
||||
return core.getInput('retention-days')
|
||||
}
|
||||
|
||||
get Endpoint(): string {
|
||||
return core.getInput('nextcloud-url')
|
||||
get Endpoint(): URL {
|
||||
return new URL(core.getInput('nextcloud-url', { required: true }))
|
||||
}
|
||||
|
||||
get Username(): string {
|
||||
return core.getInput('nextcloud-username')
|
||||
return core.getInput('nextcloud-username', { required: true })
|
||||
}
|
||||
|
||||
get Password(): string {
|
||||
return core.getInput('nextcloud-password')
|
||||
return core.getInput('nextcloud-password', { required: true })
|
||||
}
|
||||
|
||||
get Token(): string {
|
||||
@@ -32,7 +29,7 @@ export class ActionInputs implements Inputs {
|
||||
}
|
||||
|
||||
get NoFileBehvaior(): NoFileOption {
|
||||
const notFoundAction = core.getInput('if-no-files-found') || NoFileOption.warn
|
||||
const notFoundAction = core.getInput('if-no-files-found', { required: false }) || NoFileOption.warn
|
||||
const noFileBehavior: NoFileOption = NoFileOption[notFoundAction as keyof typeof NoFileOption]
|
||||
|
||||
if (!noFileBehavior) {
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import { URL } from 'url'
|
||||
import { NoFileOption } from './NoFileOption'
|
||||
|
||||
export interface Inputs {
|
||||
@@ -5,9 +6,7 @@ export interface Inputs {
|
||||
|
||||
readonly ArtifactPath: string
|
||||
|
||||
readonly Retention: string
|
||||
|
||||
readonly Endpoint: string
|
||||
readonly Endpoint: URL
|
||||
|
||||
readonly Username: string
|
||||
|
||||
|
@@ -7,6 +7,7 @@ import fetch, { HeadersInit } from 'node-fetch'
|
||||
import btoa from 'btoa'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import * as webdav from 'webdav'
|
||||
import { URL } from 'url'
|
||||
|
||||
const fs = fsSync.promises
|
||||
|
||||
@@ -21,7 +22,7 @@ export class NextcloudClient {
|
||||
private davClient
|
||||
|
||||
constructor(
|
||||
private endpoint: string,
|
||||
private endpoint: URL,
|
||||
private artifact: string,
|
||||
private rootDirectory: string,
|
||||
private username: string,
|
||||
@@ -29,7 +30,7 @@ export class NextcloudClient {
|
||||
) {
|
||||
this.guid = uuidv4()
|
||||
this.headers = { Authorization: 'Basic ' + btoa(`${this.username}:${this.password}`) }
|
||||
this.davClient = webdav.createClient(`${this.endpoint}/remote.php/dav/files/${this.username}`, {
|
||||
this.davClient = webdav.createClient(`${this.endpoint.href}remote.php/dav/files/${this.username}`, {
|
||||
username: this.username,
|
||||
password: this.password
|
||||
})
|
||||
@@ -150,7 +151,7 @@ export class NextcloudClient {
|
||||
}
|
||||
|
||||
private async shareFile(remoteFilePath: string): Promise<string> {
|
||||
const url = this.endpoint + `/ocs/v2.php/apps/files_sharing/api/v1/shares`
|
||||
const url = `${this.endpoint.href}ocs/v2.php/apps/files_sharing/api/v1/shares`
|
||||
const body = {
|
||||
path: remoteFilePath,
|
||||
shareType: 3,
|
||||
@@ -174,7 +175,7 @@ export class NextcloudClient {
|
||||
core.debug(`Match groups:\n${JSON.stringify(match?.groups)}`)
|
||||
const sharableUrl = (match?.groups || {})['share_url']
|
||||
if (!sharableUrl) {
|
||||
throw new Error('Failed to parse sharable URL.')
|
||||
throw new Error(`Failed to parse or find sharable URL:\n${result}`)
|
||||
}
|
||||
|
||||
return sharableUrl
|
||||
|
Reference in New Issue
Block a user