-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(domain): set rootpath for all files
- Loading branch information
Showing
9 changed files
with
98 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package domain | ||
|
||
import "path/filepath" | ||
|
||
type AnimeFile string | ||
|
||
const malidFile AnimeFile = "malid.json" | ||
const anidbFile AnimeFile = "malid-anidbid.json" | ||
const tvdbFile AnimeFile = "malid-anidbid-tvdbid.json" | ||
const tmdbFile AnimeFile = "malid-anidbid-tvdbid-tmdbid.json" | ||
const shinkroFile AnimeFile = "for-shinkro.json" | ||
|
||
type AnimePath string | ||
|
||
var MalIDPath AnimePath | ||
var AniDBIDPath AnimePath | ||
var TVDBIDPath AnimePath | ||
var TMDBIDPath AnimePath | ||
var shinkroPath AnimePath | ||
|
||
func SetAnimePaths(rootDir string) { | ||
rootDir = setshinkrodb(rootDir) | ||
MalIDPath = makeAnimePath(rootDir, malidFile) | ||
AniDBIDPath = makeAnimePath(rootDir, anidbFile) | ||
TVDBIDPath = makeAnimePath(rootDir, tvdbFile) | ||
TMDBIDPath = makeAnimePath(rootDir, tmdbFile) | ||
shinkroPath = makeAnimePath(rootDir, shinkroFile) | ||
} | ||
|
||
func makeAnimePath(rootDir string, af AnimeFile) AnimePath { | ||
return AnimePath(filepath.Join(rootDir, string(af))) | ||
} | ||
|
||
func setshinkrodb(rootDir string) string { | ||
return filepath.Join(rootDir, "shinkrodb") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package domain | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
) | ||
|
||
func copyFileIfNotExist(srcPath, dstPath AnimePath) error { | ||
// Check if the destination file exists | ||
if _, err := os.Stat(string(dstPath)); err == nil { | ||
fmt.Printf("File %s already exists, skipping copy.\n", dstPath) | ||
return nil // File exists, no need to copy | ||
} else if !os.IsNotExist(err) { | ||
return fmt.Errorf("failed to check destination file: %v", err) | ||
} | ||
|
||
// Open the source file | ||
srcFile, err := os.Open(string(srcPath)) | ||
if err != nil { | ||
return fmt.Errorf("failed to open source file: %v", err) | ||
} | ||
defer srcFile.Close() | ||
|
||
// Create the destination file | ||
dstFile, err := os.Create(string(dstPath)) | ||
if err != nil { | ||
return fmt.Errorf("failed to create destination file: %v", err) | ||
} | ||
defer dstFile.Close() | ||
|
||
// Copy the contents from src to dst | ||
_, err = io.Copy(dstFile, srcFile) | ||
if err != nil { | ||
return fmt.Errorf("failed to copy content: %v", err) | ||
} | ||
|
||
fmt.Printf("File copied from %s to %s successfully.\n", srcPath, dstPath) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters